0

I have problem with this code:

 for(int i2=0;i2<ftdata.size();i2++){
        System.out.println("FTDATASIZE: " +ftdata.get(i2)); // here pass and shows null
        String test=ftdata.get(i2); // here gets Null Pointer Exception ????
        if(test.equals("null")){

        }
    }

System.out shows in LogCat "FTDATASIZE: null" but I get error with this line "String test=ftdata.get(i2);" I dont get it? why I get Null Pointer Exception?

    04-07 05:42:36.309: I/System.out(12983): STDATASIZE: 1
    04-07 05:42:36.309: I/System.out(12983): FTDATASIZE: 1
    04-07 05:42:36.309: I/System.out(12983): FTDATASIZE: null
    04-07 05:42:36.309: W/dalvikvm(12983): threadid=10: thread exiting with uncaught exception (group=0x40166560)
    04-07 05:42:36.309: E/AndroidRuntime(12983): FATAL EXCEPTION: Thread-11
    04-07 05:42:36.309: E/AndroidRuntime(12983): java.lang.NullPointerException
    04-07 05:42:36.309: E/AndroidRuntime(12983):    at soft.ProDb.distanceRunsMonthly(ProDb.java:22718)
    04-07 05:42:36.309: E/AndroidRuntime(12983):    at soft.ProDb.runsMonthly(ProDb.java:22593)
    04-07 05:42:36.309: E/AndroidRuntime(12983):    at soft.SHtmlM.exportALLHtml(StringaHtmlM.java:111)
    04-07 05:42:36.309: E/AndroidRuntime(12983):    at soft.ProDb$1.run(ProDb.java:12714)
    04-07 05:42:36.309: E/AndroidRuntime(12983):    at java.lang.Thread.run(Thread.java:1019)

OK Fixed

this works for me

 if(ftdata.size()==1&& ftdata.get(0)==null){
        ftdata=stdata;
    }

Just wanted to test if ftdata.get(0) is null or not

4
  • please post a stack trace from logcat... Commented Apr 7, 2013 at 2:55
  • ftdata.get(i2) is null and cann't to pass the null value to the string??? Commented Apr 7, 2013 at 2:56
  • This is not an android specific question Commented Apr 7, 2013 at 3:01
  • and this is not Android "04-07 05:42:36.309: E/AndroidRuntime(12983):" ?! Commented Apr 7, 2013 at 3:07

2 Answers 2

4

The null pointer is on the line if(test.equals("null")){ because test is null and you are trying to call .equals() on it.

If you are trying to check that the String is null, use if (test == null) instead

If you are trying to check that the String has the value "null", use if ("null".equals(test)) instead

Sign up to request clarification or add additional context in comments.

1 Comment

you are right! but how can I to pass the null value to string so that test="null" ? must wait 5min to accept
1

try this:

for(int i2=0;i2<ftdata.size();i2++){
        System.out.println("FTDATASIZE: " +ftdata.get(i2));
        String test; 
        if(ftdata.get(i2)!=null){
            test = ftdata.get(i2);
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.