PDA

Click to See Complete Forum and Search --> : .equals not ?


DaoK
Nov 20th, 2001, 12:34 PM
How can i do that :

while ((sLigne = br.readLine()).equals (null));

but I do not one .equals but a NOT equals I do not find how with a String

filburt1
Nov 20th, 2001, 12:42 PM
BTW, assignment in an if is considered bad, so...

sLigne = br.readLine();
while (!sLigne.equals(null))
{
// do stuff
sLigne = br.readLine(); // this must be the last thing in the while loop
}

DaoK
Nov 20th, 2001, 01:07 PM
Thx you Turtle, and thank for the tip :)

DaoK
Nov 20th, 2001, 01:36 PM
while (!(sLigne = br.readLine()).equals(null))
{
count+=1;
System.out.println(sLigne);
DiviserNomChiffre();
}

here is what I got into the DOS window:

AppAccelerator(tm) 1.2.010 for Java (JDK 1.2), x86 version.
Copyright (c) 1997-1999 Inprise Corporation. All Rights Reserved.
Patrick 16435
Jonathan 55433
+douard 33344
Babiche 34432
Roger 11112
Joe Dassin 45543
Ricky 34431 //This is the real last name but it continue
java.lang.reflect.InvocationTargetException: java.lang.NullPointerException:
at tp3.tp3.LireFichier(tp3.java:50)
at tp3.tp3.Menu(tp3.java:34)
at tp3.tp3.main(tp3.java:17)
at java.lang.reflect.Method.invoke(Native Method)
at com.borland.jbuilder.util.BootStrap.invokeMain(Unknown Source)
at com.borland.jbuilder.util.BootStrap.main(Unknown Source)

Press Ctrl+C to terminate the application...

filburt1
Nov 20th, 2001, 03:59 PM
Why not just chuck it in a try/catch block?

BTW, me no speako that French crap. :D :p Also, you can simply count+=1 to count++.

DaoK
Nov 20th, 2001, 04:05 PM
The problem is there : .equals(null)) IT DO NOT read the null :(

filburt1
Nov 20th, 2001, 04:07 PM
But it is throwing an exception which you can catch.


try
{
while (!(sLigne = br.readLine()).equals(null))
{
count+=1;
System.out.println(sLigne);
DiviserNomChiffre();
}
}
catch (Exception e)
{
System.out.println("read last line");
}

DaoK
Nov 20th, 2001, 06:13 PM
I will test that :)

CaptainPinko
Nov 21st, 2001, 10:06 AM
NULL is not a constanst in Java but an object... sort of. NULL compared to anything, even itself, returns false.

Good luck trying to get around it.

Dillinger4
Nov 21st, 2001, 10:45 AM
The keyword literal null is used to identify the fact that an object is not assigned to a variable. It can be used with any variable that is not of the primative type.

Remember that a literal denotes a constant value. ;)