android - Glide not working with my custom gallery -


i have gallery, using memory.

i wanted implement glide, wont work.

my public imageadapter class:

public class imageadapter extends baseadapter {     private layoutinflater minflater;     private activity context;      public imageadapter() {         minflater = (layoutinflater) getsystemservice(context.layout_inflater_service);      }      public int getcount() { return count; }      public object getitem(int position) {         return position;     }      public long getitemid(int position) {         return position;     }       public view getview(int position, view convertview, viewgroup parent) {         final viewholder holder;         if (convertview == null) {             holder = new viewholder();             convertview = minflater.inflate(                     r.layout.galleryitem, null);             holder.imageview = (imageview) convertview.findviewbyid(r.id.thumbimage);             holder.checkbox = (checkbox) convertview.findviewbyid(r.id.itemcheckbox);             holder.checkbox.setid(position);             holder.imageview.setid(position);             convertview.settag(holder);         } else {             holder = (viewholder) convertview.gettag();         }           view.onclicklistener clicklistener = new view.onclicklistener() {               public void onclick(view v) {                 int id = holder.checkbox.getid();                  if (thumbnailsselection[id]) {                     holder.checkbox.setchecked(false);                     thumbnailsselection[id] = false;                 } else {                     holder.checkbox.setchecked(true);                     thumbnailsselection[id] = true;                 }             }          };          holder.checkbox.setonclicklistener(clicklistener);         holder.imageview.setonclicklistener(clicklistener);          holder.imageview.setonlongclicklistener(new view.onlongclicklistener() {              public boolean onlongclick(view v) {                 // todo auto-generated method stub                 int id = v.getid();                 intent intent = new intent();                 intent.setaction(intent.action_view);                 intent.setdataandtype(uri.parse("file://" + arrpath[id]), "image/*");                 startactivity(intent);                 return true;             }          });         holder.imageview.setimagebitmap(thumbnails[position]);         holder.checkbox.setchecked(thumbnailsselection[position]);         holder.id = position;           glide.with(context).load(holder.imageview)                 .placeholder(r.drawable.logo).centercrop()                 .into((imageview) convertview);          return convertview;     } }  class viewholder {     imageview imageview;     checkbox checkbox;     int id; } 

oncreate method:

 gridview imagegrid = (gridview) findviewbyid(r.id.phoneimagegrid);  imagegrid.setadapter(new imageadapter()); 

logcat:

java.lang.nullpointerexception: attempt invoke virtual method 'boolean android.app.activity.isdestroyed()' on null object reference @ com.bumptech.glide.manager.requestmanagerretriever.assertnotdestroyed(requestmanagerretriever.java:133) @ com.bumptech.glide.manager.requestmanagerretriever.get(requestmanagerretriever.java:125) @ com.bumptech.glide.glide.with(glide.java:641) @ com.example.example.photonet.gallery$imageadapter.getview(gallery.java:170) 

i had cast convertview imageview androidstudio accept it.

without glide part works well. problem in part.

change

note: use context. need context sohail zahid answer here

glide.with(context).load("url")             .placeholder(r.drawable.logo).centercrop()             .into(holder.imageview); 

for load sdcard need follow this

 string filename = "1.jpg";  string completepath = environment.getexternalstoragedirectory() + "/" + filename;  file file = new file(completepath); uri imageuri = uri.fromfile(file);  glide.with(this)         .load(imageuri)                 .into(holder.imageview); 

Comments