我在我的android项目中使用Volley Library,我一直在努力使用这段代码。如果可以的话,有没有人能够体验到这一点。
logcat的
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.grafiq.testviewapp/com.example.grafiq.testviewapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2694)
MainActivity.java onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openActivity = (Button)findViewById(R.id.btn_Child);
myrecyclerView = (RecyclerView)findViewById(R.id.myRecycleView);
myrecyclerView.setLayoutManager(new LinearLayoutManager(this));
//Request Que
RequestQueue myRequest = VolleySingleton.getInstance().getRequestQue();
//JsonObjectRequest
JsonObjectRequest myJsonReq = new JsonObjectRequest(Request.Method.GET, myUrl, null, new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject jsonObject) {
Toast.makeText(MainActivity.this, "JSON-RESPONSE "+jsonObject.toString() ,Toast.LENGTH_LONG).show();
adapter = new MyAdapter(MainActivity.this, popArray(jsonObject));
myrecyclerView.setAdapter(adapter);
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(MainActivity.this, "RESPONSE "+volleyError.getMessage() ,Toast.LENGTH_LONG).show();
}
});
myRequest.add(myJsonReq);
}