|
-
Nov 20th, 2001, 01:34 PM
#1
.equals not ?
How can i do that :
Code:
while ((sLigne = br.readLine()).equals (null));
but I do not one .equals but a NOT equals I do not find how with a String
-
Nov 20th, 2001, 01:42 PM
#2
Member
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
}
-
Nov 20th, 2001, 02:07 PM
#3
Thx you Turtle, and thank for the tip
-
Nov 20th, 2001, 02:36 PM
#4
Code:
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...
-
Nov 20th, 2001, 04:59 PM
#5
-
Nov 20th, 2001, 05:05 PM
#6
The problem is there : .equals(null)) IT DO NOT read the null
-
Nov 20th, 2001, 05:07 PM
#7
Member
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");
}
-
Nov 20th, 2001, 07:13 PM
#8
I will test that
-
Nov 21st, 2001, 11:06 AM
#9
Hyperactive Member
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.
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Nov 21st, 2001, 11:45 AM
#10
Dazed Member
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.
Last edited by Dilenger4; Nov 21st, 2001 at 11:49 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|