当我重新打开应用程序ArrayList时,不会从射击中存储价值



这是主要活动代码。当我有时打开应用程序时,它会显示数据,有时不会显示。我发现有时会列表列表null。

这是主要活动代码。当我有时打开应用程序时,它会显示数据,有时不会显示。我发现有时候阵列列表null null。 凌空

    StringRequest r = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
           Log.d("code",response);

            JSONObject obj = null;
            try {
                obj = new JSONObject(response);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            JSONArray gallary = null;
            try {
                gallary = obj.getJSONArray("arr");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < gallary.length(); i++) {
                JSONObject a = null;
                try {
                    a = gallary.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String PostId = null;
                try {
                    PostId = a.getString("Name");
                    list.add(new dataclass("mmmmm"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                Log.d("List", String.valueOf(list));
                goahed();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(MainActivity.this,"error",Toast.LENGTH_LONG).show();
        }
    });
    RequestQueue queue= Volley.newRequestQueue(this);
    queue.add(r);
    RecyclerView rv=findViewById(R.id.demolist);


    list.add(new dataclass("please"));
    for (Integer j=0;j < list.size();j++){
    }

    // Creating Adapter Object
    listdemoAdpter adapter=new listdemoAdpter(this,list);
    //Set layout Manager
    rv.setLayoutManager(new LinearLayoutManager(this));
    // set Adapter
    rv.setAdapter(adapter);

我将射击图库用于API电话预先感谢

if(list.isempty()){
   RecyclerView rv=findViewById(R.id.demolist);
   list.add(new dataclass("please"));
   for (Integer j=0;j < list.size();j++){
    }
   // Creating Adapter Object
   listdemoAdpter adapter=new listdemoAdpter(this,list);
   //Set layout Manager
   rv.setLayoutManager(new LinearLayoutManager(this));
  // set Adapter
  rv.setAdapter(adapter);

}else{
 //logic when list is empty and request again in volly

}

最新更新