安卓 2.3.3
我有一个 ArrayList,有 3 个值。当我试图从数组列表中检索值时,我得到一个 NullPointerException。我正在尝试从arraylist 中获取值并将其设置为textview。
这是代码:::
System.out.println(alAngleResult.toString());
txtViewResult.setText("");
int i = 0;
while(i < alAngleResult.size())
{
txtViewResult.append(alAngleResult.get(i).toString());
// Exception at above line
txtViewResult.append("\n");
i++;
}
LogCat 输出 :::
01-25 01:32:26.599: I/System.out(18437): [10.0 Degrees, 0.17453292519943295 Radians, 10.0 Gradians] => Output
01-25 01:32:26.599: W/dalvikvm(18437): threadid=1: thread exiting with uncaught exception (group=0x40184560)
01-25 01:32:26.599: E/AndroidRuntime(18437): FATAL EXCEPTION: main
01-25 01:32:26.599: E/AndroidRuntime(18437): java.lang.NullPointerException
01-25 01:32:26.599: E/AndroidRuntime(18437): at com.xx.xx.xx.performConvertionForAngle(UnitConverter.java:416)
01-25 01:32:26.599: E/AndroidRuntime(18437): at com.xx.xx.xx.performConvertion(UnitConverter.java:368)
01-25 01:32:26.599: E/AndroidRuntime(18437): at com.xx.xx.xx.onClick(UnitConverter.java:356)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.view.View.performClick(View.java:2485)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.view.View$PerformClick.run(View.java:9080)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.os.Handler.handleCallback(Handler.java:587)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.os.Looper.loop(Looper.java:130)
01-25 01:32:26.599: E/AndroidRuntime(18437): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-25 01:32:26.599: E/AndroidRuntime(18437): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 01:32:26.599: E/AndroidRuntime(18437): at java.lang.reflect.Method.invoke(Method.java:507)
01-25 01:32:26.599: E/AndroidRuntime(18437): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
01-25 01:32:26.599: E/AndroidRuntime(18437): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
01-25 01:32:26.599: E/AndroidRuntime(18437): at dalvik.system.NativeStart.main(Native Method)
编辑 ::: 只需要清理项目。它现在工作正常。