我正在尝试调用不同的活动,具体取决于输入的密码是否正确。但我总是收到一个 NullPointerException 强制关闭我的应用程序。
我的代码:
Intent MainScreenIntent = new Intent("com.shr.khg.Login");
startActivity(MainScreenIntent);
我的清单:
<activity
android:name="com.shr.khg.LoginActivity"
android:label="@string/title_activity_login" >
<intent-filter>
<action android:name="com.shr.khg.Login" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
日志:
04-01 20:05:59.221: D/dalvikvm(1846): GC_FOR_ALLOC freed 34K, 4% free 8624K/8963K, paused 57ms
04-01 20:05:59.230: I/dalvikvm-heap(1846): Grow heap (frag case) to 9.514MB for 1024016-byte allocation
04-01 20:05:59.320: D/dalvikvm(1846): GC_FOR_ALLOC freed <1K, 4% free 9624K/9991K, paused 58ms
04-01 20:05:59.460: D/dalvikvm(1846): GC_CONCURRENT freed <1K, 4% free 9624K/9991K, paused 5ms+14ms
04-01 20:06:05.860: D/AndroidRuntime(1846): Shutting down VM
04-01 20:06:05.860: W/dalvikvm(1846): threadid=1: thread exiting with uncaught exception (group=0x40014760)
04-01 20:06:05.870: E/AndroidRuntime(1846): FATAL EXCEPTION: main
04-01 20:06:05.870: E/AndroidRuntime(1846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shr.khg/com.shr.khg.LoginActivity}: java.lang.NullPointerException
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread.access$500(ActivityThread.java:122)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.os.Looper.loop(Looper.java:132)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread.main(ActivityThread.java:4123)
04-01 20:06:05.870: E/AndroidRuntime(1846): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 20:06:05.870: E/AndroidRuntime(1846): at java.lang.reflect.Method.invoke(Method.java:491)
04-01 20:06:05.870: E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-01 20:06:05.870: E/AndroidRuntime(1846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-01 20:06:05.870: E/AndroidRuntime(1846): at dalvik.system.NativeStart.main(Native Method)
04-01 20:06:05.870: E/AndroidRuntime(1846): Caused by: java.lang.NullPointerException
04-01 20:06:05.870: E/AndroidRuntime(1846): at com.shr.khg.LoginActivity.setup(LoginActivity.java:98)
04-01 20:06:05.870: E/AndroidRuntime(1846): at com.shr.khg.LoginActivity.onCreate(LoginActivity.java:89)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.Activity.performCreate(Activity.java:4397)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-01 20:06:05.870: E/AndroidRuntime(1846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
04-01 20:06:05.870: E/AndroidRuntime(1846): ... 11 more
我做错了什么?我只是不明白,因为它看起来适用于我的所有其他活动,但不适用于那个。
谢谢!