Question

My code:

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();
        }
    }
}

Error:

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: 
Was it helpful?

Solution

try to change

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;    
}

to this.

  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;    
}

OTHER TIPS

On this line

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

you are starting your AsyncTask passing imgurl as parameter. However, at that time imgurl is still an empty string (""). So you would need to set

imgurl = imgstore + image;

before executing the taks/before passing imgurl as a parameter to the task.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top