在android中使用volley时在gridview中获取null值

时间:2014-12-24 05:59:50

标签: android android-volley

我正在使用volley库从android中的服务器获取数据。我正在使用两个请求来检索数据。第一个请求应在第二个请求之前检索所有数据所以我使用优先级按顺序处理。 Now First请求在第二个请求之前检索所有数据。但我在两个请求过程后做了一些计算。使用上述两个请求的结果进行计算。问题是,一旦我加载计算部分被执行,之后我的数据从服务器检索。所以我得到了null。那么在我的请求部分之后我的计算方法是什么。

这是我的代码:

final Priority priority = Priority.HIGH;
    JsonArrayRequest req1 = new JsonArrayRequest("http://xxexample.com/android/prabalam.php",
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response1) {
                    Log.d(TAG, response1.toString());
                    //msgResponse.setText(response.toString());
                    jArray1=response1;
                    try
                    {
                    for(int i=0;i<jArray1.length();i++)
                    {
                    jObj1=jArray1.getJSONObject(i);

                    name=jObj1.getString("name");
                    aname.add(name);
                    roll=jObj1.getString("roll");
                    aroll.add(roll);
                    intro=jObj1.getString("intro");
                    aintro.add(intro);
                    mobile_no=jObj1.getString("mobile_no");
                    amobileno.add(mobile_no);
                    ma_no=jObj1.getString("manager_no");
                    amano.add(ma_no);
                    s_no=jObj1.getString("s_no");
                    asno.add(s_no);

                    //hideProgressDialog1();
                    }
                    }
                    catch(Exception e)
                    {
                        System.out.println("caught exception prabalam.php"+e.getMessage());
                    }

                    System.out.println(" ;name"+aname);
                    System.out.println(";roll.."+aroll);
                    System.out.println(";intro"+aintro);
                    //msgResponse.setText(mimg.get(0));

                    //ImageLoader imageLoader = AppController.getInstance().getImageLoader();

                    // If you are using NetworkImageView
                    //imgNetWorkView.setImageUrl(mimg.get(0), imageLoader);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    //msgResponse.setText(error.getMessage());
                    //hideProgressDialog1();
                }
            }){
        public Priority getPriority() {
            return priority;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req1,
            tag_json_arry);


    //showProgressDialog1();
    final Priority priority1 = Priority.NORMAL;
    JsonArrayRequest req2 = new JsonArrayRequest("http://iexample.com/android/pr_images.php",
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response2) {
                    Log.d(TAG, response2.toString());
                    //msgResponse.setText(response.toString());
                    jArray2=response2;
                    try
                    {
                    for(int i=0;i<jArray2.length();i++)
                    {
                    jObj2=jArray2.getJSONObject(i);
                    img=jObj2.getString("images");
                    images.add(img);
                    snoo=jObj2.getString("s_no");
                    sno.add(snoo);
                    pnoo=jObj2.getString("p_no");
                    pno.add(pnoo);

                    //hideProgressDialog1();
                    }
                    }
                    catch(Exception e1)
                    {
                        System.out.println("caught exception pr_images.php"+e1.getMessage());
                    }

                    System.out.println("images name"+images);
                    System.out.println("sno.."+sno);
                    System.out.println("pno.."+pno);


                    //msgResponse.setText(mimg.get(0));

                    //ImageLoader imageLoader = AppController.getInstance().getImageLoader();

                    // If you are using NetworkImageView
                    //imgNetWorkView.setImageUrl(mimg.get(0), imageLoader);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    //msgResponse.setText(error.getMessage());
                    //hideProgressDialog1();
                }
            })
    {
        public Priority getPriority() {
            return priority1;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req2,
            tag_json_arry);     


String v2=null;
        for(int u=0;u<pno.size();u++)
        {
            String v1=pno.get(u);
            String vpho=images.get(u);

            if((fno1.size())==0)
            {
                fphoto1.add(vpho);
                fno1.add(v1);
            }
            else
            {
                Boolean gh=false;

                if(v2.equals(v1))
                {
                    gh=false;
                }

                for(int k=0;k<ff1.size();k++)
                {
                String wee=ff1.get(k);
                if(wee.equals(v1))
                {
                    gh=false;
                }
                else
                {
                    gh=true;
                }
                }
                if(gh)
                {
                    fphoto1.add(vpho);
                    fno1.add(v1);
                }
            }
            ff1=fno1;
            v2=v1;
        }

        if(a.equals("nulll"))
        {
            for(int z=0;z<aroll.size();z++)
            {
                String valall=aroll.get(z);
            if(valall.equals("New Face Male"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("New face male dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("New Face Female"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("New face female.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Child"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("child.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);
            }
            else if(valall.equals("Villan"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("villan.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Comedy"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("comedy.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Film Director"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("film director dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Lyric Writer"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("lyric writer dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Cinematographer"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("cinematographer.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Cine Designer"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("cine designer.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Art Director"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("art director.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Music Director"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("music director.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);
            }
            else if(valall.equals("Play Back Singer"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("play back singer.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }
            else if(valall.equals("Still Photographer"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));  

                System.out.println("photographer.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);
            }
            else if(valall.equals("Stunt Director"))
            {
                dname.add(aname.get(z));
                dphoto.add(fphoto1.get(z));
                droll.add(aroll.get(z));
                dsno.add(asno.get(z));

                System.out.println("stunt director.. dname"+dname);
                System.out.println("dphoto"+dphoto);
                System.out.println("droll.."+droll);
                System.out.println("dsno.."+dsno);

            }

            }
            resim_list=new ArrayList<String>();
            resim_list.addAll(dphoto);
            resim_name=new ArrayList<String>();
            resim_name.addAll(dname);
            rolll=new ArrayList<String>();
            rolll.addAll(droll);
            mobile=new ArrayList<String>();
            mobile.addAll(dsno);

            System.out.println("resim list"+resim_list);
            System.out.println("resim name"+resim_name);
            System.out.println("rolll.."+rolll);
            System.out.println("mobile.."+mobile);

        }

}

当我使用基本方法检索数据时,它工作正常。任何人都可以帮助我吗?

0 个答案:

没有答案