Android : FATAL EXCEPTION: main -


i new in android studio. creating tab swipe. while executing getting error fatal execption.

logcat

 2497-2497/com.polus.binil.test e/androidruntime﹕ fatal exception: main process: com.polus.binil.test, pid: 2497 java.lang.runtimeexception: unable start activity componentinfo{com.polus.binil.test/com.polus.binil.test.mainactivity}: java.lang.nullpointerexception         @ android.app.activitythread.performlaunchactivity(activitythread.java:2184)         @ android.app.activitythread.handlelaunchactivity(activitythread.java:2233)         @ android.app.activitythread.access$800(activitythread.java:135)         @ android.app.activitythread$h.handlemessage(activitythread.java:1196)         @ android.os.handler.dispatchmessage(handler.java:102)         @ android.os.looper.loop(looper.java:136)         @ android.app.activitythread.main(activitythread.java:5001)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601)         @ dalvik.system.nativestart.main(native method)             caused by: java.lang.nullpointerexception         @ com.polus.binil.test.mainactivity.oncreate(mainactivity.java:42)         @ android.app.activity.performcreate(activity.java:5231)         @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087)         @ android.app.activitythread.performlaunchactivity(activitythread.java:2148 

  here mainactivity

mainactivity

  import android.os.bundle;   import android.support.v4.app.fragmentactivity;   import android.support.v4.app.fragmenttransaction;   import android.support.v4.view.viewpager;   import android.support.v7.app.actionbar;      public class mainactivity extends fragmentactivity implements actionbar.tablistener {   private viewpager viewpager; private tabspageradapter madapter; private android.app.actionbar actionbar;   // tab titles private string[] tabs = {"top rated", "games", "movies"};  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // initilization     viewpager = (viewpager) findviewbyid(r.id.pager);     actionbar = getactionbar();     madapter = new tabspageradapter(getsupportfragmentmanager());  viewpager.setadapter(madapter); actionbar.sethomebuttonenabled(true); actionbar.setnavigationmode(android.app.actionbar.navigation_mode_tabs);        // adding tabs     (string tab_name : tabs) {         actionbar.addtab(actionbar.newtab().settext(tab_name)                 .settablistener((android.app.actionbar.tablistener) this));      }      viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() {         @override         public void onpagescrolled(int i, float v, int i2) {          }          @override         public void onpageselected(int position) {             actionbar.setselectednavigationitem(position);         }          @override         public void onpagescrollstatechanged(int i) {          }     });  }  @override public void ontabselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) {     viewpager.setcurrentitem(tab.getposition()); }  @override public void ontabunselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) {  }  @override public void ontabreselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) {  } } 

can 1 please resolve issue

actionbar = getactionbar(); 

it'll null, because extend fragmentactivity here doesn't support action bars. replace actionbaractivity , change getactionbar() getsupportactionbar().


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -