您好我的tabhost使用android
需要一些帮助问题是当我点击将启动tab活动的列表项时,它会在调试器或日志cat中没有错误而崩溃。 标签主机可以控制3个或更多活动,标签小部件嵌套在水平滚动视图中...我知道它不是滚动视图导致它崩溃,因为它在我添加它之前崩溃了。
这是我的标签活动代码:
public class BulbaTab extends TabActivity {
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tablay);
// create the TabHost that will contain the Tabs
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec tab1 = tabHost.newTabSpec("Dex Entry");
tab1.setIndicator("Dex Entry");
tab1.setContent(new Intent(this,Bulbasaur.class));
TabHost.TabSpec tab2 = tabHost.newTabSpec("Moves List");
tab2.setIndicator("Moves");
tab2.setContent(new Intent(this,BulbasaurMovesList.class));
TabHost.TabSpec tab3 = tabHost.newTabSpec("Evolution & Breeding");
tab3.setIndicator("Evolution & Breeding");
tab3.setContent(new Intent(this,BulbasaurBreeding.class));
// Set the Tab name and Activity
// that will be opened when particular Tab will be selected
/** Add the tabs to the TabHost to display. */
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
}
}
这是tabhost的布局:
TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost"
LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/horizontalScrollView"
TabWidget
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
TabWidget
HorizontalScrollView
FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
FrameLayout
LinearLayout
TabHost
必须删除不会在网站上显示的标记
这里显示错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.metaruptdonations.MetaDex/net.metaruptdonations.MetaDex.BulbaTab}: java.lang.RuntimeException: Unable to start activity ComponentInfo{net.metaruptdonations.MetaDex/net.metaruptdonations.MetaDex.Bulbasaur}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{net.metaruptdonations.MetaDex/net.metaruptdonations.MetaDex.Bulbasaur}:
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2140)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
at android.widget.TabHost.setCurrentTab(TabHost.java:413)
at android.widget.TabHost.addTab(TabHost.java:240)
at net.metaruptdonations.MetaDex.BulbaTab.onCreate(BulbaTab.java:39)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at net.metaruptdonations.MetaDex.Bulbasaur.onCreate(Bulbasaur.java:48)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2140)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
at android.widget.TabHost.setCurrentTab(TabHost.java:413)
at android.widget.TabHost.addTab(TabHost.java:240)
at net.metaruptdonations.MetaDex.BulbaTab.onCreate(BulbaTab.java:39)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
答案 0 :(得分:0)
HorizontalScrollView只能有一个子视图,你需要像这样更改你的xml
<services>
<service name="HelloService.HelloService" behaviorConfiguration="defaultBehavior">
<endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetaDataExchange"></endpoint>
<!--<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mexBinding" contract="System.ServiceModel.Description.IMetadataExchange" />-->
<host>
<baseAddresses>
<add baseAddress="http://10.135.32.65:8080/"/>
<add baseAddress="net.tcp://localhost:8090/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="defaultBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>