How can i do that :
but I do not one .equals but a NOT equals I do not find how with a StringCode:while ((sLigne = br.readLine()).equals (null));
Printable View
How can i do that :
but I do not one .equals but a NOT equals I do not find how with a StringCode:while ((sLigne = br.readLine()).equals (null));
BTW, assignment in an if is considered bad, so...
Code:sLigne = br.readLine();
while (!sLigne.equals(null))
{
// do stuff
sLigne = br.readLine(); // this must be the last thing in the while loop
}
Thx you Turtle, and thank for the tip :)
here is what I got into the DOS window:Code:while (!(sLigne = br.readLine()).equals(null))
{
count+=1;
System.out.println(sLigne);
DiviserNomChiffre();
}
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...
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++.
The problem is there : .equals(null)) IT DO NOT read the null :(
But it is throwing an exception which you can catch.
Code:try
{
while (!(sLigne = br.readLine()).equals(null))
{
count+=1;
System.out.println(sLigne);
DiviserNomChiffre();
}
}
catch (Exception e)
{
System.out.println("read last line");
}
I will test that :)
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.
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. ;)