';android.content.Context.getResources()';关于空对象引用

';android.content.Context.getResources()';关于空对象引用,android,json,nullpointerexception,android-volley,Android,Json,Nullpointerexception,Android Volley,我正在使用volley库从json文件接收数据我有这个问题我不知道这个错误的原因 尝试对空对象引用调用虚拟方法“android.content.Context.getResources()” 更新此行: RequestQueue RequestQueue=Volley.newRequestQueue(getActivity()) 与 RequestQueue RequestQueue=Volley.newRequestQueue(getContext()) 或 RequestQueue Requ

我正在使用volley库从json文件接收数据我有这个问题我不知道这个错误的原因

尝试对空对象引用调用虚拟方法“android.content.Context.getResources()”

更新此行:

RequestQueue RequestQueue=Volley.newRequestQueue(getActivity())

RequestQueue RequestQueue=Volley.newRequestQueue(getContext())


RequestQueue RequestQueue=Volley.newRequestQueue(getApplicationContext())

尝试使用应用程序context@DimaKozhevin请告诉我如何使用应用程序上下文?事实上,我正在处理片段,因此无法添加
getApplciationConetxt()
那么我应该做什么,应该添加哪个
getContext()
getActivity().getApplciationConetxt()
  private void fetchRemoteData(final DataStatus callback){
    StringRequest stringRequest = new StringRequest(Request.Method.GET,
            URL_DATA,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {

                    List<Post> listItems = new ArrayList<>();
                    try {
                        JSONObject jsonObject = new JSONObject(s);
                        JSONArray array = jsonObject.getJSONArray("bgs");
                        for (int i = 0; i < array.length(); i++){
                            JSONObject o = array.getJSONObject(i);
                            Post item = new Post(
                                    o.getString("img")
                            );
                            listItems.add(item);
                        }
                        callback.onSuccess(listItems);
                    } catch (JSONException e) {
                    }

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.onError(error);
                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
    requestQueue.add(stringRequest);
}
@Override
                public void onErrorResponse(VolleyError error) {
                    callback.onError(error);
                }