-1

Based on different SO questions I understand what the java.null.pointer exception is I am just not sure why it occurs in this case. In summary a reference to a variable declared as a reference type not yet defined.

I have 2 java files RegisterActivity.java and AppController.java.

The following call in the RegisterActivity.java file results in a java.null.pointer exception:

AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

This is the method in the AppController file:

public static synchronized AppController getInstance() { return mInstance; }

public class AppController extends Application {

    public static final String TAG = AppController.class.getSimpleName();

    private RequestQueue mRequestQueue;

    private static AppController mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
    }

    public static synchronized AppController getInstance() {
        return mInstance;
    }


//RegisterActivity.java
 public class RegisterActivity extends Activity {
 ...
     private void registerUser(final String name, final String email,
                          final String password) {
          ...
          AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
     }

 ...
 }

07-01 16:33:17.757 995-995/mobi.blessd.user.blessd E/AndroidRuntime: FATAL EXCEPTION: main Process: mobi.blessd.user.blessd, PID: 995 java.lang.NullPointerException at mobi.blessd.user.blessd.activity.RegisterActivity.registerUser(RegisterActivity.java:189) at mobi.blessd.user.blessd.activity.RegisterActivity.access$300(RegisterActivity.java:35) at mobi.blessd.user.blessd.activity.RegisterActivity$1.onClick(RegisterActivity.java:84) at android.view.View.performClick(View.java:4508) at android.view.View$PerformClick.run(View.java:18675) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5584) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method)

My source code is from the following tutorial http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35

1 Answers1

2

Did you add the AppControler 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">
Igoranze
  • 1,506
  • 13
  • 35