android - Asynctask (DownloadImageTask) failure -


if know last question, 4 activities randomly crashing. follow-up.

i tried implementing worker thread recommended me, asynctask code i've put in isn't working. i've tried looking @ stack overflow , android documentation no avail. there way working?

here's code:

    package tk.test.wirewizard;      import android.app.activity;     import android.content.intent;     import android.graphics.bitmap;     import android.os.asynctask;     import android.os.bundle;     import android.view.menu;     import android.view.menuitem;     import android.view.view;     import android.widget.button;     import android.widget.imageview;      import tk.test.wirewizard.r;        public class hdmi extends activity {     imageview mimageview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_hdmi);      button b1 = (button) findviewbyid(r.id.button);     button b2 = (button) findviewbyid(r.id.button2);       b1.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             intent = new intent(hdmi.this, rcawire.class);             hdmi.this.startactivity(i);         }     });     b2.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             intent = new intent(hdmi.this, start.class);             hdmi.this.startactivity(i);          }       });       new downloadimagetask().execute("http://ecx.images-amazon.com/images/i/61tchc9qyel._sl290_.jpg"); }  private class downloadimagetask extends asynctask<string, void, bitmap> implements tk.test.wirewizard.downloadimagetask {     /**      * system calls perform work in worker thread ,      * delivers parameters given asynctask.execute()      */     protected bitmap doinbackground(string... urls) {         return loadimagefromnetwork(urls[0]);     }      private bitmap loadimagefromnetwork(string url) {         return null;     }      /**      * system calls perform work in ui thread , delivers      * result doinbackground()      */     protected void onpostexecute(bitmap result) {         mimageview.setimagebitmap(result);      }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.hdmi, menu);         return true;     }       @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();         if (id == r.id.action_settings) {             return true;         }              return true;         }      }  } 

hopefully able work out.

thanks!

you returning null doinbackground() method , try set result bitmap imageview.

this throw nullpointerexception(because result in onpostexecute() is, of course, null) , hence crashing app.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -