Android application crashes when callling Intent -
android application crashes when call intent
give proper solution
public class informationactivity extends activity { button btn_submit; checkbox iz_check,bc_check,vc_check,ac_check,uc_check; edittext no_et; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_info); btn_submit = (button) findviewbyid(r.id.btnsubmit1); iz_check= (checkbox) findviewbyid(r.id.check1); bc_check=(checkbox) findviewbyid(r.id.check2); vc_check=(checkbox) findviewbyid(r.id.check3); ac_check=(checkbox) findviewbyid(r.id.check4); uc_check=(checkbox) findviewbyid(r.id.check5); no_et=(edittext) findviewbyid(r.id.edittext7); btn_submit.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub //string str = no_et.gettext().tostring(); //smsreceiver receiver = new smsreceiver(); intent navigationintent = new intent(informationactivity.this, mainactivity.class); startactivity(navigationintent); } }); } }
please give me solution
code
package info.androidhive.slidingmenu; import info.androidhive.slidingmenu.adapter.navdrawerlistadapter; import info.androidhive.slidingmenu.model.navdraweritem; import java.util.arraylist; import android.app.activity; import android.app.fragment; import android.app.fragmentmanager; import android.content.res.configuration; import android.content.res.typedarray; import android.os.bundle; import android.support.v4.app.actionbardrawertoggle; import android.support.v4.widget.drawerlayout; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.listview; public class mainactivity extends activity { private drawerlayout mdrawerlayout; private listview mdrawerlist; private actionbardrawertoggle mdrawertoggle; // nav drawer title private charsequence mdrawertitle; // used store app title private charsequence mtitle; / / slide menu items private string[] navmenutitles; private typedarray navmenuicons; private arraylist < navdraweritem > navdraweritems; private navdrawerlistadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mtitle = mdrawertitle = gettitle(); // load slide menu items navmenutitles = getresources().getstringarray(r.array.nav_drawer_items); // nav drawer icons resources navmenuicons = getresources() .obtaintypedarray(r.array.nav_drawer_icons); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerlist = (listview) findviewbyid(r.id.list_slidermenu); navdraweritems = new arraylist < navdraweritem > (); // adding nav drawer items array // home navdraweritems.add(new navdraweritem(navmenutitles[0], navmenuicons.getresourceid(0, -1))); // find people navdraweritems.add(new navdraweritem(navmenutitles[1], navmenuicons.getresourceid(1, -1))); // photos navdraweritems.add(new navdraweritem(navmenutitles[2], navmenuicons.getresourceid(2, -1))); // communities, add counter here navdraweritems.add(new navdraweritem(navmenutitles[3], navmenuicons.getresourceid(3, -1), true, "22")); // pages navdraweritems.add(new navdraweritem(navmenutitles[4], navmenuicons.getresourceid(4, -1))); // what's hot, add counter here navdraweritems.add(new navdraweritem(navmenutitles[5], navmenuicons.getresourceid(5, -1), true, "50+")); // recycle typed array navmenuicons.recycle(); mdrawerlist.setonitemclicklistener(new slidemenuclicklistener()); // setting nav drawer list adapter adapter = new navdrawerlistadapter(getapplicationcontext(), navdraweritems); mdrawerlist.setadapter(adapter); // enabling action bar app icon , behaving toggle button getactionbar().setdisplayhomeasupenabled(true); getactionbar().sethomebuttonenabled(true); mdrawertoggle = new actionbardrawertoggle(this, mdrawerlayout, r.drawable.ic_drawer, //nav menu toggle icon r.string.app_name, // nav drawer open - description accessibility r.string.app_name // nav drawer close - description accessibility ) { public void ondrawerclosed(view view) { getactionbar().settitle(mtitle); // calling onprepareoptionsmenu() show action bar icons invalidateoptionsmenu(); } public void ondraweropened(view drawerview) { getactionbar().settitle(mdrawertitle); // calling onprepareoptionsmenu() hide action bar icons invalidateoptionsmenu(); } }; mdrawerlayout.setdrawerlistener(mdrawertoggle); if (savedinstancestate == null) { // on first time display view first nav item displayview(0); } } /** * slide menu item click listener * */ private class slidemenuclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview < ? > parent, view view, int position, long id) { // display view selected nav drawer item displayview(position); } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // toggle nav drawer on selecting action bar app icon/title if (mdrawertoggle.onoptionsitemselected(item)) { return true; } // handle action bar actions click switch (item.getitemid()) { case r.id.action_settings: return true; default: return super.onoptionsitemselected(item); } } /* * * called when invalidateoptionsmenu() triggered */ @override public boolean onprepareoptionsmenu(menu menu) { // if nav drawer opened, hide action items boolean draweropen = mdrawerlayout.isdraweropen(mdrawerlist); menu.finditem(r.id.action_settings).setvisible(!draweropen); return super.onprepareoptionsmenu(menu); } /** * diplaying fragment view selected nav drawer list item * */ private void displayview(int position) { // update main content replacing fragments fragment fragment = null; switch (position) { case 0: fragment = new homefragment(); break; case 1: fragment = new findpeoplefragment(); break; case 2: fragment = new photosfragment(); break; case 3: fragment = new communityfragment(); break; case 4: fragment = new pagesfragment(); break; case 5: fragment = new whatshotfragment(); break; default: break; } if (fragment != null) { fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.frame_container, fragment).commit(); // update selected item , title, close drawer mdrawerlist.setitemchecked(position, true); mdrawerlist.setselection(position); settitle(navmenutitles[position]); mdrawerlayout.closedrawer(mdrawerlist); } else { // error in creating fragment log.e("mainactivity", "error in creating fragment"); } } @override public void settitle(charsequence title) { mtitle = title; getactionbar().settitle(mtitle); } /** * when using actionbardrawertoggle, must call during * onpostcreate() , onconfigurationchanged()... */ @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); // sync toggle state after onrestoreinstancestate has occurred. mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); // pass configuration change drawer toggls mdrawertoggle.onconfigurationchanged(newconfig); } }
logcat's log:
01-27 14:09:49.668: d/androidruntime(27312): shutting down vm 01-27 14:09:49.668: w/dalvikvm(27312): threadid=1: thread exiting uncaught exception (group=0x41625bc0) 01-27 14:09:49.668: e/androidruntime(27312): fatal exception: main 01-27 14:09:49.668: e/androidruntime(27312): process: info.androidhive.slidingmenu, pid: 27312 01-27 14:09:49.668: e/androidruntime(27312): java.lang.runtimeexception: unable start activity componentinfo{info.androidhive.slidingmenu/info.androidhive.slidingmenu.mainactivity}: java.lang.nullpointerexception 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread.performlaunchactivity(activitythread.java:2342) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2392) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread.access$800(activitythread.java:151) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread$h.handlemessage(activitythread.java:1266) 01-27 14:09:49.668: e/androidruntime(27312): @ android.os.handler.dispatchmessage(handler.java:102) 01-27 14:09:49.668: e/androidruntime(27312): @ android.os.looper.loop(looper.java:136) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread.main(activitythread.java:5421) 01-27 14:09:49.668: e/androidruntime(27312): @ java.lang.reflect.method.invokenative(native method) 01-27 14:09:49.668: e/androidruntime(27312): @ java.lang.reflect.method.invoke(method.java:515) 01-27 14:09:49.668: e/androidruntime(27312): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:979) 01-27 14:09:49.668: e/androidruntime(27312): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:795) 01-27 14:09:49.668: e/androidruntime(27312): @ dalvik.system.nativestart.main(native method) 01-27 14:09:49.668: e/androidruntime(27312): caused by: java.lang.nullpointerexception 01-27 14:09:49.668: e/androidruntime(27312): @ info.androidhive.slidingmenu.mainactivity.oncreate(mainactivity.java:86) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activity.performcreate(activity.java:5264) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1099) 01-27 14:09:49.668: e/androidruntime(27312): @ android.app.activitythread.performlaunchactivity(activitythread.java:2282) 01-27 14:09:49.668: e/androidruntime(27312): ... 11 more
make sure have declared mainactivity in androidmanifest.xml
file. also, please post error log.
Comments
Post a Comment