错误说明

时间:2013-08-07 08:17:59

标签: android multithreading error-handling

这是我遇到的错误:

    08-07 13:50:31.175: E/AndroidRuntime(1033): FATAL EXCEPTION: main
08-07 13:50:31.175: E/AndroidRuntime(1033): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.database_demo/com.database_demo.LoginActivity}: java.lang.NullPointerException
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.os.Looper.loop(Looper.java:137)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread.main(ActivityThread.java:4898)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invokeNative(Native Method)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invoke(Method.java:511)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at dalvik.system.NativeStart.main(Native Method)
08-07 13:50:31.175: E/AndroidRuntime(1033): Caused by: java.lang.NullPointerException
08-07 13:50:31.175: E/AndroidRuntime(1033):     at com.database_demo.LoginActivity.onCreate(LoginActivity.java:92)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.Activity.performCreate(Activity.java:5206)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
08-07 13:50:31.175: E/AndroidRuntime(1033):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
08-07 13:50:31.175: E/AndroidRuntime(1033):     ... 11 more

我能够弄清楚这些错误是因为它们是在OnCreate()方法中使用网络相关的任务!我是正确的还是可能有更多的理由呢?

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.database_demo"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />      
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".DashboardActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        <!-- Control Database connection -->
        </activity>
        <activity android:name=".Database_demo"
                  android:label="Login"></activity>
        <!--  DashBoard Activity -->
        <activity
            android:label="Dash Board" 
            android:name=".LoginActivity"></activity>
    </application>


</manifest> 

2 个答案:

答案 0 :(得分:1)

您忘记为Button btnLinkToRegister;

创建对象
btnLinkToRegister = (Button) findViewById(R.id.btnRegister);

答案 1 :(得分:0)

您尚未更新清单文件,请将以下行添加到AndroidManifest.xml,它应该可以正常工作。

<activity android:name="com.database_demo.LoginActivity" />