Results 1 to 10 of 10

Thread: .equals not ?

  1. #1
    DaoK
    Guest

    .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

  2. #2
    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
    }

  3. #3
    DaoK
    Guest
    Thx you Turtle, and thank for the tip

  4. #4
    DaoK
    Guest
    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...

  5. #5
    Why not just chuck it in a try/catch block?

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

  6. #6
    DaoK
    Guest
    The problem is there : .equals(null)) IT DO NOT read the null

  7. #7
    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");
    }

  8. #8
    DaoK
    Guest
    I will test that

  9. #9
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    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

  10. #10
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width