0

我正在尝试调用不同的活动,具体取决于输入的密码是否正确。但我总是收到一个 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

我做错了什么?我只是不明白,因为它看起来适用于我的所有其他活动,但不适用于那个。

谢谢!

4

3 回答 3

0

创建意图以启动新活动的语法ActivityBActivityA

Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivity(intent);

你的语法错误。日志显示 NullPointerException 在您的LoginActivity. 请从这两行发布代码。

于 2013-04-02T10:48:09.980 回答
0

您正在进行的活动的 onCreate 有问题。问题是您的应用程序在需要对象的情况下尝试使用 null。

于 2014-07-19T02:35:24.113 回答
0

我现在找到了答案,我不小心将错误的布局分配给了活动,因此它无法设置处理程序。

于 2013-04-02T13:15:57.397 回答