未找到协议

时间:2014-04-21 09:39:52

标签: java android android-bitmap

我的代码:

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: 

2 个答案:

答案 0 :(得分:0)

在这一行

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

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

imgurl = imgstore + image;

之前执行taks /之前imgurl作为参数传递给任务。

答案 1 :(得分: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;    
}