我制作了一个简单的android应用程序,它以长度5编辑文本输入从一个 Activity 移动到另一个 Activity 。但是我得到了异常(exception)。我已经附加了两个Java文件(MainActicity和另一个),mainfest文件和logcat输出。有人请帮助我。
提前致谢。

下载链接:: http://www.4shared.com/folder/gyDYjAYC/AndroidApp.html

logcat是:

08-10 16:15:47.289: D/AndroidRuntime(4043): Shutting down VM
08-10 16:15:47.296: W/dalvikvm(4043): threadid=1: thread exiting with uncaught exception (group=0x40018578)
08-10 16:15:47.296: E/AndroidRuntime(4043): FATAL EXCEPTION: main
08-10 16:15:47.296: E/AndroidRuntime(4043): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.practice/com.example.practice.Another}: java.lang.NullPointerException
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.os.Looper.loop(Looper.java:130)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at java.lang.reflect.Method.invoke(Method.java:507)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at dalvik.system.NativeStart.main(Native Method)
08-10 16:15:47.296: E/AndroidRuntime(4043): Caused by: java.lang.NullPointerException
08-10 16:15:47.296: E/AndroidRuntime(4043):     at com.example.practice.Another.onCreate(Another.java:18)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-10 16:15:47.296: E/AndroidRuntime(4043):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-10 16:15:47.296: E/AndroidRuntime(4043):
... 11 more

最佳答案

Another类中:

Bundle c= getIntent().getExtras();
String s= c.getString("key");

在此代码中,c为null,因为android不会对启动程序Intent进行任何额外设置。

关于android - 在Android中获取运行时异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11900467/

10-10 15:58