0
My code is so
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);
}
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 may be going on?
Have you seen if the variable
response
is not void?– gabrielhof
I managed to solve! puts after much lost time
– Guilherme