为什么我不能将位图添加到位图arraylist

时间:2013-09-19 10:36:50

标签: android arraylist bitmap

为什么我无法在asynktask中的位图数组列表中添加位图。

public static class YourMoves_Players extends AsyncTask<String, String, String> {

//  static String yourmove_players[];
    @Override
    protected String doInBackground(String... args) {

        boolean failure = false;
        // TODO Auto-generated method stub
         // Check for success tag
       int success;

       Log.d("login.on create","YOURMOVE_PLAYERS Background");
       try {
           // Building Parameters
           List<NameValuePair> params = new ArrayList<NameValuePair>();

           params.add(new BasicNameValuePair("playerid", fb_id));//player_id
           Log.d("request!", "starting");

           //Posting user data to script 
           JSONObject json = jsonParser.makeHttpRequest(
                  GETYOURMOVE_URL, "POST", params);
           if(json == null)
           {
            Log.d("json","json returning null");
               return null;
           }

           success = json.getInt(TAG_SUCCESS);
           if (success == 1) {

            products = json.getJSONArray(TAG_PRODUCTS);

            Log.d("Notification","BEFORE FOR LOOP");
            Log.d("",products.length()+" LENGTH");
                for (int i = 0; i < products.length(); i++) {
                    JSONObject c = products.getJSONObject(i);

                    String yourmove_pid = c.getString(TAG_YOURMOVE_ID); 
                    String player_name = c.getString(TAG_YOURMOVE_NAME);

                //  yourmove_pic.add(Get_FB_Image.getFBImage(yourmove_pid));
                    Players player=new Players(yourmove_pid,player_name);
                    yourmove_list.add(player);
                    yourmove_id.add(yourmove_pid);
                    yourmove.add(player_name);
                    Log.d("Vs_facebook","going to add bitmap facebook image");
                    yourmove_pic.add(Get_FB_Image.getFBImage(yourmove_pid));
                    Log.d("Vs_facebook"," facebook image added");
            Log.d("User Created!", json.toString()+"CONGRETS");
                }


                Log.d("","AFTER FOR LOOP yourmove_id  "+yourmove_id);
            return json.getString(TAG_MESSAGE);
           }else{
            Log.d("Login Failure!", "SUCCESS FAILED");
            return json.getString(TAG_MESSAGE);

           }
       } catch (JSONException e) {
           e.printStackTrace();
       }
       catch(Exception e){}

       return null;

    }
    /**
    * After completing background task Dismiss the progress dialog
    * **/


} 

“yourmove_pic”是位图数组列表,“Get_FB_Image.getFBImage(yourmove_pid)”是从中获取用户的facebook个人资料图像的方法。但我的应用程序在执行此行之前卡住了在执行此行之前,我正在打印我正在打印的日志消息 那有什么问题请帮忙

我的Logcat消息-----&gt;

09-19 10:21:48.999: I/Choreographer(2115): Skipped 77 frames!  The application may be doing too much work on its main thread.
09-19 10:21:49.300: I/Choreographer(2115): Skipped 194 frames!  The application may be doing too much work on its main thread.
09-19 10:21:49.350: D/Vs_facebook(2115): inside on start
09-19 10:21:49.390: D/(2115): Vs_FACEBOOK ON RESUME BEFORE ShowList
09-19 10:21:52.509: D/login.on create(2115): YOURMOVE_PLAYERS Background
09-19 10:21:52.560: D/request!(2115): starting
09-19 10:21:54.980: D/Notification(2115): BEFORE FOR LOOP
09-19 10:21:54.980: D/(2115): 4 LENGTH
09-19 10:21:55.000: D/Vs_facebook(2115): going to add bitmap facebook image
在我的getFBImage中

我正在获取这样的个人资料图片

URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+fb_id+"/picture?type=small");
fb_image = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
return fb_image;

2 个答案:

答案 0 :(得分:0)

根据我的说法,这应该是通过内存出错的例外并处理它,这里有一些链接可以帮助你解决这个问题: Out of memory Error using List,LinkedList and HashMap

可以处理Out of memory Error using LRU Cache

答案 1 :(得分:0)

也许Get_FB_Image.getFBImage(yourmove_pid)解码流并返回位图。如果是这种情况,那么生成位图的流的解码还没有完成,为什么应用程序在获取位图时会卡住。