java - Android TabHost not working. I haven't done any mistake -


i have created app show tabhost. when launch application on emulator closes saying app unfortunately closed. searched internet can't find solution. code activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity">   <tabhost     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:id="@+id/tabhost"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true">      <linearlayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:orientation="vertical">          <tabwidget             android:id="@android:id/tabs"             android:layout_width="fill_parent"             android:layout_height="wrap_content"></tabwidget>          <framelayout             android:id="@android:id/tabcontent"             android:layout_width="fill_parent"             android:layout_height="fill_parent">              <linearlayout                 android:id="@+id/tab1"                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:orientation="vertical">              </linearlayout>              <linearlayout                 android:id="@+id/tab2"                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:orientation="vertical"></linearlayout>              <linearlayout                 android:id="@+id/tab3"                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:orientation="vertical"></linearlayout>         </framelayout>     </linearlayout> </tabhost> 

mainactivity.java

public class mainactivity extends actionbaractivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      tabhost tabhost=(tabhost)findviewbyid(r.id.tabhost);      tabspec tab1 = tabhost.newtabspec("first tab");     tabspec tab2 = tabhost.newtabspec("second tab");     tabspec tab3 = tabhost.newtabspec("third tab");      tab1.setindicator("tab1");     tab1.setcontent(new intent(this,tab1activity.class));      tab2.setindicator("tab2");     tab2.setcontent(new intent(this,tab2activity.class));      tab3.setindicator("tab3");     tab3.setcontent(new intent(this,tab3activity.class));      tabhost.addtab(tab1);     tabhost.addtab(tab2);     tabhost.addtab(tab3); } 

i have created separate .java files tab1,tab2 , tab3.

logcat is

06-01 01:40:35.429 1847-1847/com.realtech.june_1_tab w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0xa4cd3b20) 06-01 01:40:35.441 1847-1847/com.realtech.june_1_tab e/androidruntime﹕ fatal exception: main process: com.realtech.june_1_tab, pid: 1847 java.lang.runtimeexception: unable start activity componentinfo{com.realtech.june_1_tab/com.realtech.june_1_tab.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 @ android.widget.tabhost.addtab(tabhost.java:236) @ com.realtech.june_1_tab.mainactivity.oncreate(mainactivity.java:34) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) @ 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) 06-01 01:42:24.121 1847-1847/com.realtech.june_1_tab i/process﹕ sending signal. pid: 1847 sig: 9

you have 1 mistake. in layout xml file, tabhost id use default setting @+id/tabhost not run, have change @android:id/tabhost.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -