Volley AppController class object returning null

前端 未结 4 1790
温柔的废话
温柔的废话 2021-01-19 12:46

I am making an app that makes a JsonObjectRequest and retrieves a JSON data from an URL using the Volley Networking Library for android.

AppCon

4条回答
  •  遇见更好的自我
    2021-01-19 13:23

    Don't you forget to initialize the RequestQueue Object. You need to initialize the RequestQueue inside the onCreate method, like you can see in the example:
    (Else when you call request.add(jsonObjectRequest) the application will try to reference the null object)

    RequestQueue request;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //request qwe
        request= Volley.newRequestQueue(this);
    }
    

提交回复
热议问题