java - Android activity is returning null through intent -
not sure why keep getting null reference when trying return data main activity activity (done through intents). i've tried serialize everything, , tried other stuff. don't know may causing it. can 1 point out mistake?
here error keep getting:
java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=10, result=0, data=null} activity {ebadly.com.youstreamer/ebadly.com.youstreamer.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'java.io.serializable android.content.intent.getserializableextra(java.lang.string)' on null object reference
here code in mainactivity class:
public static final int pick_contacts = 10; public arraylist<contact> msendphonenumbers; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); msendphonenumbers = new arraylist<contact>(); button contactsbutton = (button)findviewbyid(r.id.select_contacts_button); contactsbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(mainactivity.this, contactslistactivity.class); i.putextra(contactslistactivity.extra, msendphonenumbers); startactivityforresult(i, pick_contacts); } }); button enterbutton = (button)findviewbyid(r.id.enter_button); enterbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } }); } enter code here @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); msendphonenumbers = (arraylist<contact>)data.getserializableextra(contactslistactivity.extra); }
here code contactslistactivity class:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_contacts_list); msendphonenumbers = new arraylist<contact>(); msendphonenumbers = (arraylist<contact>) getintent().getserializableextra(extra); mcontacts = new arraylist<contact>(); cursor phones = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, null, null, null); while (phones.movetonext()) { contact c = new contact(); c.mname = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.display_name)); c.mnumber = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.number)); mcontacts.add(c); } phones.close(); if(!msendphonenumbers.isempty() || msendphonenumbers != null){ for(contact c : msendphonenumbers){ if(c.mchecked == true){ for(contact search: mcontacts){ if(search.mnumber.equals(c.mnumber)){ search.mchecked = true; } } } } } mcontactslist = (listview) findviewbyid(r.id.contact_list); mcontactslist.setadapter(new contactlistviewadapter(mcontacts)); mcontactslist.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { contact c = (contact) parent.getadapter().getitem(position); if(c.mchecked == true) c.mchecked = false; else c.mchecked = true; } }); } @override public void onbackpressed(){ super.onbackpressed(); for(contact addcontact: mcontacts){ if (addcontact.mchecked){ for(contact search : msendphonenumbers){ if(search.mnumber.equals(addcontact.mnumber)){ break; }else msendphonenumbers.add(addcontact); } } } intent = new intent(); log.d("hereee === ", msendphonenumbers.tostring()); i.putextra(extra, msendphonenumbers); setresult(result_ok, i); finish(); }
Comments
Post a Comment