"FATAL EXCEPTION: main java.lang.NullPointerException" error in android

0

My code is like this

private void makeJsonArryReq() {
    showProgressDialog();
    JsonArrayRequest req = new JsonArrayRequest(Const.URL_JSON_ARRAY,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG, response.toString());
                    //msgResponse.setText(response.toString());
                    hideProgressDialog();

                    int aJsonint = 0;
                    String aJsonString;

                    try {
                        JSONArray jsonarray = response;
                        JSONObject jsonobj;

                        for (int i=0; i<jsonarray.length(); i++){
                            jsonobj = jsonarray.getJSONObject(i);

                            aJsonString = jsonobj.getString("sigla");
                            aJsonint = jsonobj.getInt("id");
                            System.out.println("ID " + aJsonint + " sigla  " + aJsonString);

                            nomes.add(aJsonString);

                            //Identifica o Spinner no layout

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();
                }
            });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req,tag_json_arry);

    // Cancelling request
     //ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_arry);

    spn1 = (Spinner) findViewById(R.id.spinner);
    //Cria um ArrayAdapter usando um padrão de layout da classe R do android, passando o ArrayList nomes
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, nomes);
    ArrayAdapter<String> spinnerArrayAdapter = arrayAdapter;
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spn1.setAdapter(spinnerArrayAdapter);
}

The error is appearing like this:

09-17 16:01:56.751    2190-2190/com.example.guilherme.vendows E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
        at com.example.guilherme.vendows.JsonRequestActivity.makeJsonArryReq(JsonRequestActivity.java:172)
        at com.example.guilherme.vendows.JsonRequestActivity.onClick(JsonRequestActivity.java:192)
        at android.view.View.performClick(View.java:4084)
        at android.view.View$PerformClick.run(View.java:16966)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

09-17 16: 02: 21,330 2190-2190 / com.example.guilherme.vendows I / Process: Sending signal. PID: 2190 SIG: 9

What can happen?

    
asked by anonymous 17.09.2014 / 21:08

1 answer

1

I needed to declare this in AndroidManifest.xml

<application
    android:name="com.example.guilherme.vendows.AppController"  ---> faltava isso agora funciona perfeitamente
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".JsonRequestActivity"/>
</application>
    
17.09.2014 / 21:18