我正在尝试创建一个包含4个标签的活动。代码:
public class ManagerActivity extends Activity implements OnTabChangeListener {
private TabHost th;
private Intent Tab1Intent;
private Intent Tab2Intent;
private Intent Tab3Intent;
private Intent Tab4Intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.manager);
th = (TabHost) findViewById(android.R.id.tabhost);
th.setup();
InitTabs(th);
th.setOnTabChangedListener(this);
}
private void InitTabs(TabHost th) {
TabSpec specs = th.newTabSpec("tag1");
specs.setIndicator("עדכון הודעות");
Tab1Intent = new Intent(this, UpdateMessagesActivity.class);
specs.setContent(Tab1Intent);
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setIndicator("עדכון אירועים");
Tab2Intent = new Intent(this, UpdateEventsActivity.class);
specs.setContent(Tab1Intent);
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setIndicator("עדכון זמני השבת");
Tab3Intent = new Intent(this, updateShabathTimesActivity.class);
specs.setContent(Tab1Intent);
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setIndicator("עדכון זמני יום חול");
Tab4Intent = new Intent(this, UpdateDaysTimesActivity.class);
specs.setContent(Tab1Intent);
th.addTab(specs);
}
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
if (tabId.equals("tag1")) {
startActivity(Tab1Intent);
} else if (tabId.equals("tag2")) {
startActivity(Tab1Intent);
} else if (tabId.equals("tag3")) {
startActivity(Tab1Intent);
} else {
startActivity(Tab1Intent);
}
}
}
现在,由于某种原因,只要尝试在InitTabs(th)方法调用中创建选项卡和规范,应用程序就会崩溃。在这个方法中,它到达第一行,将选项卡添加到选项卡主机,然后崩溃。我该如何解决这个问题?
日志:
02-14 12:03:14.749: E/Trace(774): error opening trace file: No such file or directory (2)
02-14 12:03:15.674: D/gralloc_goldfish(774): Emulator without GPU emulation detected.
02-14 12:03:24.273: D/dalvikvm(774): GC_FOR_ALLOC freed 90K, 8% free 2620K/2832K, paused 38ms, total 51ms
02-14 12:03:24.283: I/dalvikvm-heap(774): Grow heap (frag case) to 3.280MB for 635812-byte allocation
02-14 12:03:24.433: D/dalvikvm(774): GC_FOR_ALLOC freed 11K, 7% free 3230K/3456K, paused 145ms, total 145ms
02-14 12:03:24.493: D/dalvikvm(774): GC_CONCURRENT freed <1K, 7% free 3241K/3456K, paused 5ms+21ms, total 63ms
02-14 12:03:24.813: I/Choreographer(774): Skipped 63 frames! The application may be doing too much work on its main thread.
02-14 12:03:25.613: D/InputEventConsistencyVerifier(774): KeyEvent: ACTION_UP but key was not down.
02-14 12:03:25.613: D/InputEventConsistencyVerifier(774): in android.widget.EditText{40de01a8 VFED..CL .F....I. 0,59-456,118 #7f08003b app:id/password}
02-14 12:03:25.613: D/InputEventConsistencyVerifier(774): 0: sent at 112787000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=112787, downTime=112699, deviceId=0, source=0x101 }
02-14 12:03:28.993: D/dalvikvm(774): GC_CONCURRENT freed 95K, 6% free 3541K/3756K, paused 5ms+6ms, total 120ms
02-14 12:03:29.353: D/AndroidRuntime(774): Shutting down VM
02-14 12:03:29.363: W/dalvikvm(774): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
02-14 12:03:29.444: E/AndroidRuntime(774): FATAL EXCEPTION: main
02-14 12:03:29.444: E/AndroidRuntime(774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.neotavraham/com.example.neotavraham.ManagerActivity}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.os.Looper.loop(Looper.java:137)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-14 12:03:29.444: E/AndroidRuntime(774): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 12:03:29.444: E/AndroidRuntime(774): at java.lang.reflect.Method.invoke(Method.java:511)
02-14 12:03:29.444: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-14 12:03:29.444: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-14 12:03:29.444: E/AndroidRuntime(774): at dalvik.system.NativeStart.main(Native Method)
02-14 12:03:29.444: E/AndroidRuntime(774): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
02-14 12:03:29.444: E/AndroidRuntime(774): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:747)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.widget.TabHost.addTab(TabHost.java:240)
02-14 12:03:29.444: E/AndroidRuntime(774): at com.example.neotavraham.ManagerActivity.InitTabs(ManagerActivity.java:49)
02-14 12:03:29.444: E/AndroidRuntime(774): at com.example.neotavraham.ManagerActivity.onCreate(ManagerActivity.java:38)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.Activity.performCreate(Activity.java:5104)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-14 12:03:29.444: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-14 12:03:29.444: E/AndroidRuntime(774): ... 11 more
02-14 12:03:32.503: I/Process(774): Sending signal. PID: 774 SIG: 9
02-14 12:03:34.043: D/gralloc_goldfish(798): Emulator without GPU emulation detected.