我有一个包含 ListView 和 TabHost 的 Activity。在这个 TabHost 中,我试图添加另一个 Activity,但它一直在我身上崩溃。知道是什么原因造成的吗?
public class MainActivity extends RoboFragmentActivity {
@InjectView(R.id.listView)
private ListView listView;
@InjectView(R.id.tabHost)
private TabHost tabHost;
@Inject
IIntentProxy intentProxy;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
tabHost.setup();
TabHost.TabSpec spec = tabHost.newTabSpec("tag");
spec.setContent(intentProxy.getIntent(DetailActivity.class));
spec.setIndicator("Title");
// It crashes on line below
// tabHost is not null, neither is spec
tabHost.addTab(spec);
}
}
.
<LinearLayout 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:orientation="horizontal"
android:weightSum="100" >
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
</FrameLayout>
</TabWidget>
</LinearLayout>
</TabHost>
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50" >
</ListView>
</LinearLayout>
详细活动被添加到 tabhost xml 文件不包含任何内容,只是一个 LinearLayout
public class DetailActivity extends RoboActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_activity);
}
}
堆栈跟踪
12-24 18:06:03.535: E/AndroidRuntime(27143): FATAL EXCEPTION: main
12-24 18:06:03.535: E/AndroidRuntime(27143): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.app/com.company.app.pages.MainActivity}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.os.Handler.dispatchMessage(Handler.java:99)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.os.Looper.loop(Looper.java:137)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-24 18:06:03.535: E/AndroidRuntime(27143): at java.lang.reflect.Method.invokeNative(Native Method)
12-24 18:06:03.535: E/AndroidRuntime(27143): at java.lang.reflect.Method.invoke(Method.java:511)
12-24 18:06:03.535: E/AndroidRuntime(27143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-24 18:06:03.535: E/AndroidRuntime(27143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-24 18:06:03.535: E/AndroidRuntime(27143): at dalvik.system.NativeStart.main(Native Method)
12-24 18:06:03.535: E/AndroidRuntime(27143): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:747)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.widget.TabHost.addTab(TabHost.java:240)
12-24 18:06:03.535: E/AndroidRuntime(27143): at com.pages.ChargeSheetActivity.onCreate(ChargeSheetActivity.java:33)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.Activity.performCreate(Activity.java:5104)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-24 18:06:03.535: E/AndroidRuntime(27143): at android.app.ActivityThread.performLaunchActivity(ActivityThr
ead.java:2144) 12-24 18:06:03.535: E/AndroidRuntime(27143): ... 11 更多