我正在尝试从此网页实现此代码。
但由于某种原因,我得到了一个NullPointerException
:
08-05 08:59:09.512: E/AndroidRuntime(875): java.lang.NullPointerException
08-05 08:59:09.512: E/AndroidRuntime(875): at com.example.basiccountdown.MainActivity$1.onTick(MainActivity.java:23)
编码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
startB = (Button) this.findViewById(R.id.button);
startB.setOnClickListener(this);
text = (TextView) this.findViewById(R.id.timer);
countDownTimer = new MyCountDownTimer(startTime, interval);
text.setText(text.getText() + String.valueOf(startTime/1000));
}
更多堆栈跟踪
08-05 09:21:44.313: D/AndroidRuntime(1258): Shutting down VM
08-05 09:21:44.313: W/dalvikvm(1258): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-05 09:21:44.412: E/AndroidRuntime(1258): FATAL EXCEPTION: main
08-05 09:21:44.412: E/AndroidRuntime(1258): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.basiccountdown/com.example.basiccountdown.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.basiccountdown.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.basiccountdown-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.basiccountdown-2, /system/lib]]
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.os.Looper.loop(Looper.java:137)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-05 09:21:44.412: E/AndroidRuntime(1258): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 09:21:44.412: E/AndroidRuntime(1258): at java.lang.reflect.Method.invoke(Method.java:525)
08-05 09:21:44.412: E/AndroidRuntime(1258): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-05 09:21:44.412: E/AndroidRuntime(1258): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 09:21:44.412: E/AndroidRuntime(1258): at dalvik.system.NativeStart.main(Native Method)
08-05 09:21:44.412: E/AndroidRuntime(1258): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.basiccountdown.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.basiccountdown-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.basiccountdown-2, /system/lib]]
08-05 09:21:44.412: E/AndroidRuntime(1258): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-05 09:21:44.412: E/AndroidRuntime(1258): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-05 09:21:44.412: E/AndroidRuntime(1258): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
08-05 09:21:44.412: E/AndroidRuntime(1258): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
08-05 09:21:44.412: E/AndroidRuntime(1258): ... 11 more
08-05 09:28:51.782: D/AndroidRuntime(1307): Shutting down VM
08-05 09:28:51.782: W/dalvikvm(1307): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
第 23 行是super.onCreate(savedInstanceState);