我试图在Android中实现tabhost。Android Tabhost不工作
Radio_Debug [Android Application]
DalvikVM[localhost:8604]
Thread [<3> main] (Suspended (exception NullPointerException))
TabHost.dispatchWindowFocusChanged(boolean) line: 295
LinearLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line: 664
FrameLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line: 664
LinearLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line: 664
PhoneWindow$DecorView(ViewGroup).dispatchWindowFocusChanged(boolean) line: 664
ViewRoot.handleMessage(Message) line: 1819
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4363
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
Thread [<17> Binder Thread #4] (Running)
Thread [<15> Binder Thread #3] (Running)
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
:我已经设置它,但是当我运行页面时,我得到一个空指针异常不我的Android手机上显示tabhost控制,并生成以下堆栈跟踪方面做得正确eveything Java代码链接到XML页面代码如下:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class tabs extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabmain);
TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
}
}
,其容纳tabhost控制是如下的xml文件布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="@+id/tabHost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab1">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab3">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab4">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
你在这个tabhost里面有任何视图吗? – kosa 2012-01-08 15:35:53
是的,我已经尝试了4个文本视图,我仍然得到相同的错误。 – user615099 2012-01-08 18:59:08