我对这段代码有疑问:
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 在 LogCat "FTDATASIZE: null" 中显示,但我在这行 "String test=ftdata.get(i2);" 出现错误 我不明白?为什么我得到空指针异常?
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)
好的 固定的
这对我有用
if(ftdata.size()==1&& ftdata.get(0)==null){
ftdata=stdata;
}
只是想测试 ftdata.get(0) 是否为空