2014-04-21 79 views
-1

我的代码:协议未发现

public class MagAdapter extends ArrayAdapter<maginfo> { 
    private LayoutInflater inflater; 
    public String imgstore="http://******.com/cms/document/images/books/"; 
    public static String imgurl=""; 

    public MagAdapter(Context context,List<maginfo> newsadapter) { 
     super(context,R.layout.mag_listview,newsadapter); 
     // TODO Auto-generated constructor stub 
     inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     // TODO Auto-generated constructor stub 
    } 

    public View getView(int postion,View contentView,ViewGroup parent) { 
     View item=inflater.inflate(R.layout.mag_listview,parent,false); 

     new DisplayImageFromURL((ImageView) item.findViewById(R.id.imageView1)).execute(imgurl); 

     TextView tv1=(TextView) item.findViewById(R.id.textView1); 
     //TextView tv2=(TextView) item.findViewById(R.id.textView2); 

     //creating the object of the student 
     maginfo latestnews=getItem(postion); 
     Log.d("latestnews", latestnews.getPdf()); 

     //populate the custom list view with the class of Student 
     tv1.setText(latestnews.getTitle()); 
     //tv2.setText(latestnews.getImg()); 
     String image=latestnews.getImg(); 

     imgurl=imgstore+image; 
     Log.d("imageurl", ""+imgurl); 

     return item;  
    } 

    private class DisplayImageFromURL extends AsyncTask<String, Void, Bitmap> { 
     ImageView bmImage; 

     public DisplayImageFromURL(ImageView bmImage) { 
      this.bmImage = bmImage; 
     } 

     protected Bitmap doInBackground(String... urls) { 
      String urldisplay = urls[0]; 
      Bitmap mIcon11 = null; 
      try { 
       InputStream in = new java.net.URL(urldisplay).openStream(); 
       mIcon11 = BitmapFactory.decodeStream(in); 
      } catch (Exception e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 

      return mIcon11; 
     } 

     protected void onPostExecute(Bitmap result) { 
      bmImage.setImageBitmap(result); 
      //pd.dismiss(); 
     } 
    } 
} 

错误:

04-21 15:20:58.739: E/Error(1959): Protocol not found: 
04-21 15:20:58.739: W/System.err(1959): java.net.MalformedURLException: Protocol not found: 

回答

0

试图改变

public View getView(int postion,View contentView,ViewGroup parent) 
{ 
    View item=inflater.inflate(R.layout.mag_listview,parent,false); 

    new DisplayImageFromURL((ImageView) item.findViewById(R.id.imageView1)) 
    .execute(imgurl); 

    TextView tv1=(TextView) item.findViewById(R.id.textView1); 
    //TextView tv2=(TextView) item.findViewById(R.id.textView2); 



    //creating the object of the student 
    maginfo latestnews=getItem(postion); 
    Log.d("latestnews", latestnews.getPdf()); 

    //populate the custom list view with the class of Student 
    tv1.setText(latestnews.getTitle()); 
    //tv2.setText(latestnews.getImg()); 
    String image=latestnews.getImg(); 

    imgurl=imgstore+image; 
    Log.d("imageurl", ""+imgurl); 



    return item;  
} 

了这一点。

public View getView(int postion,View contentView,ViewGroup parent) 
    { 
    View item=inflater.inflate(R.layout.mag_listview,parent,false); 

    //creating the object of the student 
    maginfo latestnews=getItem(postion); 
    Log.d("latestnews", latestnews.getPdf()); 
    String image=latestnews.getImg(); 
    imgurl=imgstore+image; 

    new DisplayImageFromURL((ImageView) item.findViewById(R.id.imageView1)) 
    .execute(imgurl); 

    TextView tv1=(TextView) item.findViewById(R.id.textView1); 
    tv1.setText(latestnews.getTitle()); 

    return item;  
} 
0

在此行中

new DisplayImageFromURL((ImageView) item.findViewById(R.id.imageView1)).execute(imgurl); 

你开始你的AsyncTask传递imgUrl的作为参数。但是,那时imgurl仍然是一个空字符串("")。所以,你需要设置

imgurl = imgstore + image; 

之前通过imgurl作为参数的任务之前执行TAKS /。

+0

非常感谢你的工作。 – Naren

+0

为相同的代码,我得到了一个错误:04-22 12:43:57.145:D/skia(2538):--- decoder-> decode returned false – Naren