NullPointerException happens in an Android code snippet

前端 未结 2 1978
执笔经年
执笔经年 2021-01-15 05:25

Here\'s the code which deals with member registration.

public class RegisterActivity extends Activity {
    private static final String TAG = RegisterActivit         


        
相关标签:
2条回答
  • 2021-01-15 05:57

    As you can see, AppController is not added to your manifest:

    <application
            android:name=".AppController" //this one
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
    

    So onCreate never get called and mInstance is null.

    0 讨论(0)
  • 2021-01-15 06:10

    the problem is you didn't declare your Subclass of Application to the AndroidManifest. Add android:name="path.to.AppController" to the Application tag, otherwise your subclass of Application is not instantiated and mInstance remains not initialized (null by default). And that explains the NPE

     <application
        android:name="path.to.AppController"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    
    0 讨论(0)
提交回复
热议问题