解决错误位图上的URI失败错误

时间:2015-08-06 10:31:07

标签: java android

我正在尝试将Base64字符串和一些文本解码为位图,并使用hashmap将其加载到listview。文本显示在列表视图上但不显示位图,我得到“resolveuri在坏位图上失败”异常..

MainActivity

   try {
                // Getting JSON Array from URL
             details = json.getJSONArray(TAG_Root);
                for(int i = 0; i < details.length(); i++){
                JSONObject c = details.getJSONObject(i);

                 //Storing  JSON item in a Variable
                String branch = c.getString(TAG_Branch);
               String address = c.getString(TAG_Add);
                String uname = c.getString(TAG_User);
                String photo = c.getString(TAG_Photo);
                 System.out.println(photo);
               //decoding the base64 image to an png format

                byte[] imageAsBytes = Base64.decode(photo, Base64.DEFAULT);
                Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
                //ImageView image = (ImageView)findViewById(R.id.imageView1);
              // image.setImageBitmap(
                    // BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
                //);

               System.out.println();

                HashMap<String, Object> map = new HashMap<String, Object>();

                map.put(TAG_Branch, branch);
               map.put(TAG_Add, address);
               map.put(TAG_User, uname);
               map.put(TAG_Photo, bitmap);
              oslist.add(map);

              //String.valueOf(TAG_Photo
                //,R.id.imageView1
                list=(ListView)findViewById(R.id.listView1);

                ListAdapter adapter = new SimpleAdapter(MainActivity.this,      oslist,
                        R.layout.list_activity,
                        new String[] { TAG_Branch,TAG_Add, TAG_User,TAG_Photo }, new int[] {
                                R.id.textView1,R.id.textView2, R.id.textView3,R.id.imageView1});

的logcat

1 个答案:

答案 0 :(得分:0)

我认为你试图从互联网上获取位图而不是使用Asynctask。这是个坏主意。 您可以关注Google开发教程:http://developer.android.com/training/displaying-bitmaps/index.html