Mohsen Mohsen - 5 months ago 35
Android Question

NullPointerException addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference

i'm using http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ and it's working fine in example project of this login-register.(just login and register)

But, after many trys in complete app with

cardviews
and other
widgets
, it show me this
*LogCat*
:

java.lang.NullPointerException: Attempt to invoke virtual method 'void client.myproject.app.AppController.addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference
at client.myproject.RegisterActivity.registerUser(RegisterActivity.java:185)
at client.myproject.RegisterActivity.access$300(RegisterActivity.java:35)
at client.myproject.RegisterActivity$1.onClick(RegisterActivity.java:81)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)


while these codes works fine in single app(just with register login).but i have this problem.

can anyone please explain this, how we can fix this and what is the problem?

Its use Volley library and i copyed the library into the
Libs
folder in android studio.

so, what is the problem?

Cheers!

Answer

In your AndroidManifest.xml add

<application android:name="YOURPACKAGENAME.AppController" 
             android:allowbackup="true" 
             android:icon="@drawable/ic_launcher" 
             android:label="@string/app_name"
             android:theme="@style/AppTheme">
Comments