如何从数据库获取图像并将位置设置为数据?

问题描述:

这是我在vid.java类如何从数据库获取图像并将位置设置为数据?

public String LOG = "erorMessage"; 
public String url_cat = "http://10.0.3.2/fd/get_cat.php"; 
public String url_video = "http://10.0.3.2/fd/get_data.php?page="; 
public String Url_Video_by_cat = "http://10.0.3.2/fd/get_data_by_cat.php?cat="; 

的URL,这是我ImageDownloaderTask.java类

private class ImageDownloaderTask extends AsyncTask <HashMap<String , Object> , Void , HashMap<String , Object>> { 

    @Override 
    protected HashMap<String, Object> doInBackground(HashMap<String, Object>... params) { 

     InputStream myStream; 

     String imgurl = (String)params[0].get("image_path"); 

     int position = (Integer)params[0].get("position"); 


     try{ 


      URL url = new URL(imgurl); 
      HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 

      connection.setDoInput(true); 
      connection.connect(); 

      myStream = connection.getInputStream(); 

      File cachDirectory = getBaseContext().getCacheDir(); 

      File temp = new File(cachDirectory.getPath() + "/image_" + position + "_" + curent_page + ".png"); 

      FileOutputStream outputStream = new FileOutputStream(temp); 

      Bitmap b = BitmapFactory.decodeStream(myStream); 

      b.compress(Bitmap.CompressFormat.PNG , 100 , outputStream); 

      outputStream.flush(); 

      outputStream.close(); 

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

      bitmap.put("image" , temp.getPath()); 
      bitmap.put("position" , position); 


      return (bitmap); 



     }catch (Exception e){ 
      Log.i(LOG , "error in ImageDownloaderTask" + e.toString()); 
     } 


     return null; 
    } 

    @Override 
    protected void onPostExecute(HashMap<String, Object> reslut) { 


     String images = (String) reslut.get("image"); 

     int position = (Integer)reslut.get("position"); 

     SimpleAdapter adb = (SimpleAdapter) l.getAdapter(); 

     HashMap<String , Object> hms = (HashMap<String, Object>) adb.getItem(position); 

     hms.put("image" , images); 

     adb.notifyDataSetChanged(); 

    } 
} 

一切都很好,但是当我运行genymotion应用程序给强制关闭。在logcat中有错误inImageDownloaderTask

03-08 15:38:06.761 3417-3687/com.haditv.haditv I/erorMessage: error in ImageDownloaderTaskjava.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) 

,这是我videosmosoe.java类

public class Videos_mosoe { 

    List<HashMap<String, Object>> pars_video_mosoe(String json) { 

     List<HashMap<String, Object>> All_Video_mosoz = new ArrayList<>(); 

     try { 

      JSONObject joj = new JSONObject(json); 
      JSONArray jArr = joj.getJSONArray("video"); 

      for (int i = 0; i < jArr.length(); i++) { 

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

       JSONObject temp = (JSONObject) jArr.get(i); 

       Videos.put("id", temp.getString("id")); 
       Videos.put("subject", temp.getString("subject")); 
       Videos.put("image", R.drawable.ic_movie_creation_black_36dp); 
       Videos.put("image_path", temp.getString("image")); 
       Videos.put("description", temp.getString("description")); 
       Videos.put("date", temp.getString("date")); 
       Videos.put("cat_id", temp.getString("cat_id")); 

       All_Video_mosoz.add(Videos); 
      } 

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

     return (All_Video_mosoz); 

    } 

} 

10.0.2.2更换10.0.3.2或与192

+0

仍然是Proglem启动服务器的IP地址替换:无法连接到本地主机/ 127.0.0.1(端口80):连接失败:ECONNREFUSED(连接被拒绝) – rohollah

+0

我编辑答案 –