android - How do I pull a image by gridview position -


everything working picture not shown

baseadapter:

public bitmap getitem(int position) {     return bitmaps.get(position); } 

activity:

intent = new intent(getapplicationcontext(), spcifiesimage.class);                     // passing array index                     i.putextra("id", position);`enter code here`                     startactivity(i); 

this activity want image there :

intent intent = new intent(getapplicationcontext(), spcifiesimage.class);      intent = getintent();      // selected image id     int position = i.getextras().getint("id");     customgrid imageadapter = new customgrid(mcontext);      imageview imageview = (imageview) findviewbyid(r.id.imageview3);     imageview.setimagebitmap(imageadapter.bitmaps.get(position));       // passing array index     intent.putextra("mas", massage);      startactivity(intent); 

customgrid:

         context mcontext; private bitmap btimaprecieve; list<parseobject> parseobjects; arraylist<bitmap> bitmaps; parsequery<parseobject> query; progressdialog progressdialog; int size;   public customgrid(context c, arraylist<bitmap> bitmaps) {     mcontext = c;     this.bitmaps = bitmaps;  }  public customgrid(context mcontext) { }   //---returns number of images--- public int getcount() {     return bitmaps.size(); }  //---returns id of item--- public bitmap getitem(int position) {     return bitmaps.get(position); }  @override public long getitemid(int position) {     return position; }  public view getview(int position, view convertview, viewgroup parent) {      layoutinflater inflater = (layoutinflater) mcontext             .getsystemservice(context.layout_inflater_service);      view gridview;      if (convertview == null) {          gridview = new view(mcontext);          // layout mobile.xml         gridview = inflater.inflate(r.layout.mobile, null);          // set value textview        // textview textview = (textview) gridview.findviewbyid(r.id.grid_item_label);       //  textview.settext(mobilevalues[position]);          // set image based on selected text         imageview imageview = (imageview) gridview                 .findviewbyid(r.id.grid_item_image);        // imageview.setlayoutparams(new gridview.layoutparams(70, 70));        // imageview.setscaletype(imageview.scaletype.center_crop);         imageview.setimagebitmap(bitmaps.get(position));       } else {         gridview = (view) convertview;     }     return gridview; 

logcat:

process: com.example.tepper.myapplication, pid: 16637 java.lang.nullpointerexception: attempt invoke virtual method 'boolean android.graphics.bitmap.compress(android.graphics.bitmap$compressformat, int, java.io.outputstream)' on null object reference

ok, code posted, have problem part:

on customgrid:

public customgrid(context mcontext) { } 

the constructor empty means when this:

customgrid imageadapter = new customgrid(mcontext);   imageview imageview = (imageview) findviewbyid(r.id.imageview3); imageview.setimagebitmap(imageadapter.bitmaps.get(position)); 

the bitmaps array not initialized. have either make bitmap array static or store in place can accessed activity, purpose of testing this:

  • change following line on customgrid:

    arraylist<bitmap> bitmaps; public static arraylist<bitmap> bitmaps;

  • then on next activity access this:

    imageview.setimagebitmap(customgrid.bitmaps.get(position));


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -