NullPointerException addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference
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">
As N1to says, you need to add your controller in the AndroidManifest.xml
, if you don't add it then the onCreate()
is never called and when you call AppController.getInstance()
the instance is null.
<application android:name="YOURPACKAGENAME.AppController"
android:allowbackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
It also works for me with:
<application android:name=".AppController"
android:allowbackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
In my case, I forgot to initialize the variable rq, please, make sure you did it
...
private RequestQueue rq; // rq = null (NullPointerException if you use it)
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
rq = Volley.newRequestQueue(YourActivity.this); // rq != null
}
...
rq.add(request);