2014-07-03 37 views
3

我高度關注從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); 

回答

0

試試這個:

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

相關問題