.equals() NullPointer

Discussion in 'Plugin Development' started by Zarkopafilis, May 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Zarkopafilis

    Error happens here.
    Code:
    if(AString.equals("white"))
    before this , I already do :
    Code:
    setAString("white");
    , I have already tried to use a Helper method than return true if its equal or false if its not , but still same issue....any ideas?
     
  2. Offline

    kreashenz

    Are you sure its .equals()? I think it's probably AString being the NPE.
     
  3. Offline

    Zarkopafilis

    AString is "white" (I do it before this if takes place (I tried before to check while it was null but same thing))
     
  4. Offline

    kreashenz

    So, you're doing
    Code:java
    1. String AString = "white";

    ? That would be wrong. You're checking if the String equals a String.. It's pointless.. You shouldn't do that, you should check if (if it's an args) args[?].equalsIgnoreCase(AString);
     
  5. Offline

    Zarkopafilis

    Nope , I am doing :
    - A declaration on another class
    -on onEnable I call a method thats called variableInit(Sets default values for varjiables)
    I have in variableinit , anotherclass.setAString("white")
    -A scheduler runs doing some checks I can say , but stucks on anotherclass.getAString().equals("white")
    and no , I am not setting before AString to a value
     
  6. Offline

    kreashenz

    Zarkopafilis Ahhh, OK, I'm not sure what the problem is then.
     
  7. Offline

    Zarkopafilis

    Aw my god, how am I supposed to troubleshoot this thing...?
     
  8. Offline

    kreashenz

    Zarkopafilis You could try and print out the messages, and see if one of them returns null?
     
  9. Offline

    Zarkopafilis

    Still after the anotherclass.setAString("white") it returns back null :S now what?
     
  10. Offline

    kreashenz

    Maybe try fix it. Make it public, make it static, or whatever you need to do. I'm not sure.
     
  11. Offline

    Zarkopafilis

    As far as setter is public , I dont need to make it public , and static???why???Its value will be changing....
     
  12. Offline

    kreashenz

    Zarkopafilis I wasn't telling you to change it to static.. I was just suggesting in the case of it needing to be. I'm not entirely sure what the problem is at the moment.. I don't think I'm going to be much help after this, so just wait till someone more experienced come along and see this.
     
  13. Offline

    Ivan

    Zarkopafilis if the string from the other class is public, you can use otherclass.AString = "white"; because I think there is something wrong in your setAString("blablabla");
    Also are you referencing in a static manner, or are you using an instance of that class?
     
    Zarkopafilis likes this.
  14. Offline

    Zarkopafilis

    Sure helped, also I looked at a trick , instead of otherclass.AString.equals("white") , I make a string called white , give it "white" value and then , I can do white.equals(otherclass.AString)
     
  15. Zarkopafilis
    You don't need to create a variable to do that.
    Code:
    if("white".equals(otherclass.AString)) ...
    But it would be best to figure out why your AString (which is badly named by the way) is null in the first place when it should return a value.
     
  16. Offline

    Zarkopafilis

    Okay ..
     
Thread Status:
Not open for further replies.

Share This Page