从drawable文件夹中读取图像时出错

时间:2014-07-03 09:22:22

标签: android json imageview

我正在从json读取数据并在listview中显示它的活动。我希望通过检查某些条件将图像添加到listview中。但是它将错误返回给我:

07-03 14:50:48.398: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:48.408: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:48.438: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:48.458: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:48.468: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:48.998: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:49.008: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)
07-03 14:50:49.018: E/BitmapFactory(1106): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)

MainActivity

protected void onPostExecute(List<List<HashMap<String, String>>> result) {
            ArrayList<LatLng> points = null;
            PolylineOptions lineOptions = null;
            MarkerOptions markerOptions = new MarkerOptions();
            String distance = "";
            Spanned instruction;
            String turns = "";
            String duration = "";
            String str = "";
            int t = 0;
            if (result.size() < 1) {
                Toast.makeText(getBaseContext(), "No Points",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            // Traversing through all the routes
            for (int i = 0; i < result.size(); i++) {

                points = new ArrayList<LatLng>();
                lineOptions = new PolylineOptions();

                // Fetching i-th route
                List<HashMap<String, String>> path = result.get(i);

                // Fetching all the points in i-th route
                for (int j = 0; j < path.size(); j++) {
                    HashMap<String, String> point = path.get(j);

                    instruction = Html.fromHtml((String) point
                            .get("html_instructions"));
                    str = instruction.toString();
                    // Log.i("str", str);
                    distance = (String) point.get("distance_text");
                    turns = (String) point.get("maneuver");

                    double lat = Double.parseDouble(point.get("lat"));
                    double lng = Double.parseDouble(point.get("lng"));
                    LatLng position = new LatLng(lat, lng);

                    points.add(position);
                    HashMap<String, String> map1 = new HashMap<String, String>();
                    map1.put("instruction", str);
                    if (turns == "turn-left") {
                        map1.put("img", Integer.toString(img[8]));
                    }
                    else if (turns == "turn-right") {
                        map1.put("img", Integer.toString(img[9]));
                    } else if (turns == "fork-right") {
                        map1.put("img", Integer.toString(img[1]));
                    } else if (turns == "turn-slight-right") {
                        map1.put("img", Integer.toString(img[11]));
                    } else if (turns == "turn-slight-left") {
                        map1.put("img", Integer.toString(img[10]));
                    } else if(turns == "fork-left"){
                         map1.put("img", Integer.toString(img[0]));
                         }
                    else if (turns == "uturn-right") {
                        map1.put("img", Integer.toString(img[7]));
                    } else if(turns == ""){
                         map1.put("img", Integer.toString(img[2]));
                    }
                    // else if(turns == "ramp-left"){
                    // map1.put("img", Integer.toString(img[1]));
                    // }

                    //map1.put("distance", distance);
                    // map1.put("turns", Integer.toString(t));
                    oslist.add(map1);
                }

                // Adding all the points in the route to LineOptions
                lineOptions.addAll(points);
                lineOptions.width(2);
                lineOptions.color(Color.RED);

            }

            // Log.i("list", oslist.toString());
             String[] from = { "img","instruction" };

                // Ids of views in listview_layout
                int[] to = { R.id.flag,R.id.txt};

                SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), oslist, R.layout.activity_main, from, to);

            list.setAdapter(adapter);

            // tvDistanceDuration.setText("Distance:"+distance +
            // ", Duration:"+duration);

            // Drawing polyline in the Google Map for the i-th route
            map.addPolyline(lineOptions);

1 个答案:

答案 0 :(得分:0)

试试这个:

imageview.setImageDrawable(getActivity()getResources()getDrawable(R.drawable.image));