2

我有这段代码,我想在其中显示每个选项卡的新片段。

public class Second extends FragmentActivity{

private TabHost mTabHost;
private static final String TAG_1 = "tab1";
private static final String TAG_2 = "tab2";
private static final String TAG_3 = "tab3";
private static final String TAG_4 = "tab4";

Fragment srkt_fragment,srk2_fragment,holl_fragment,bink_fragment;

EditText k1_e,k2_e,al_e,alconst_e,dr_e;
float k1,k2,al,al_const,dr;
int invalid=0;
TextView emm;
EditText k2_m,k1_m;





protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);


    dr_e=(EditText)findViewById(R.id.dr_editText);
    k1_e=(EditText)findViewById(R.id.k1_editText);
    k2_e=(EditText)findViewById(R.id.k2_editText);
    al_e=(EditText)findViewById(R.id.al_editText);
    alconst_e=(EditText)findViewById(R.id.al_const_editText);
    emm=(TextView)findViewById(R.id.iolpower);


    mTabHost=(TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();


    /*68 line*/addTab("SRK/T", TAG_1, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent().setClass(Second.this, Srkt_x.class));
    addFragment(new Srkt_x(), true, FragmentTransaction.TRANSIT_NONE);
    addTab("SRK II", TAG_2, createTabDrawable(R.drawable.ic_tab_eye_unselected),new Intent().setClass(Second.this, Srk2_x.class));
    addFragment(new Srk2_x(), true, FragmentTransaction.TRANSIT_NONE);
    addTab("BINKHORST", TAG_3, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent().setClass(Second.this, Binkhorst_x.class));
    addFragment(new Binkhorst_x(), true, FragmentTransaction.TRANSIT_NONE);
    addTab("HOLLADAY", TAG_4, createTabDrawable(R.drawable.ic_tab_eye_unselected), new Intent().setClass(Second.this, Holladay_x.class));
    addFragment(new Holladay_x(), true, FragmentTransaction.TRANSIT_NONE);

/更多代码在这里/

private void addTab(String label, String tag, Drawable drawable, Intent intent) {
    TabHost.TabSpec spec = mTabHost.newTabSpec(tag);
    spec.setIndicator(createTabIndicator(label, drawable));
    spec.setContent(intent);
    intent.putExtra("AL", al);
    intent.putExtra("K1", k1);
    intent.putExtra("K2", k2);
    intent.putExtra("ALC", al_const);
    intent.putExtra("DR", dr);
    intent.putExtra("INVALID", invalid);
    mTabHost.addTab(spec);
    startActivity(intent);
}
void addFragment(Fragment fragment, boolean addToBackStack, int transition) {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.wrapfragment, fragment);//314 line
    ft.setTransition(transition);
    if (addToBackStack)
        ft.addToBackStack(null);
    ft.commit();
}

我得到以下异常

    02-13 10:26:12.734: D/AndroidRuntime(400): Shutting down VM
02-13 10:26:12.734: W/dalvikvm(400): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-13 10:26:12.744: E/AndroidRuntime(400): FATAL EXCEPTION: main
02-13 10:26:12.744: E/AndroidRuntime(400): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.iolcalci/com.example.iolcalci.Second}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.os.Looper.loop(Looper.java:123)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-13 10:26:12.744: E/AndroidRuntime(400):  at java.lang.reflect.Method.invokeNative(Native Method)
02-13 10:26:12.744: E/AndroidRuntime(400):  at java.lang.reflect.Method.invoke(Method.java:507)
02-13 10:26:12.744: E/AndroidRuntime(400):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-13 10:26:12.744: E/AndroidRuntime(400):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-13 10:26:12.744: E/AndroidRuntime(400):  at dalvik.system.NativeStart.main(Native Method)
02-13 10:26:12.744: E/AndroidRuntime(400): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:652)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.widget.TabHost.setCurrentTab(TabHost.java:326)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.widget.TabHost.addTab(TabHost.java:216)
02-13 10:26:12.744: E/AndroidRuntime(400):  at com.example.iolcalci.Second.addTab(Second.java:314)
02-13 10:26:12.744: E/AndroidRuntime(400):  at com.example.iolcalci.Second.onCreate(Second.java:68)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-13 10:26:12.744: E/AndroidRuntime(400):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-13 10:26:12.744: E/AndroidRuntime(400):  ... 11 more

我知道可以通过使用 ActivityGroup 而不是 FragmentActivity 来纠正它,但我也想使用 FragmentManager。请帮我解决这个问题(android 初学者)

4

0 回答 0