java - Android app crashes creating opening Intent -
my android app "e-mail" crashes when try open "readactivity".
the method openmail(), declared in mainactivity, should start readactivity:
public void openmail(view v, int index) { string[] mail = {"x", "y", "z"}; intent readintent = new intent(this, readactivity.class); <-- error occurs here readintent.putextra("mail", mail); startactivity(readintent); }
the method called in listviewadapter:
@override public view getview(final int position, view convertview, viewgroup parent) { holder holder = new holder(); view rowview = inflater.inflate(r.layout.listview_item, null); holder.imageview = (imageview) rowview.findviewbyid(r.id.imageview); holder.txvsendermail = (textview) rowview.findviewbyid(r.id.txvsender); holder.txvsubject = (textview) rowview.findviewbyid(r.id.txvsubject); holder.imageview.setimageresource(imageid[position]); holder.txvsendermail.settext(sendermail[position]); holder.txvsubject.settext(subject[position]); rowview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { new mainactivity().openmail(v, position); } }); return rowview; }
the error: java.lang.nullpointerexception: attempt invoke virtual method 'android.app.activitythread$applicationthread android.app.activitythread.getapplicationthread()' on null object reference
i hope can me! thank you!
you trying create new mainactivity when do
new mainactivity().openmail(v, context, position);
i think wanted this, if @ mainactivity class:
getactivity().openmail(v, context, position);
of course, dont forget add readactivity androidmanifest
Comments
Post a Comment