不幸的是该计划已经停止

时间:2014-07-18 08:43:15

标签: java android eclipse tabs runtime-error

我写了一个android程序。这有多个标签..我想当我点击一个标签(Tab1)时,显示标签的特殊视图(GalleryDemoActivity.java)..但是程序已停止工作并且无法正常工作!

代码是: SRC / Tab.java:

package com.AdMd.Plant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Tabs extends Activity  {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().hide();
        setContentView(R.layout.tabs);
        TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        Intent photosIntent = new Intent(this, GalleryDemoActivity.class);
        spec1.setContent(photosIntent);
        spec1.setIndicator("اطلاعات گیاه");

        TabSpec spec2=tabHost.newTabSpec("Tab 2");
        spec2.setIndicator("گالری تصاویر");
        spec2.setContent(R.id.tab2);

        TabSpec spec3=tabHost.newTabSpec("Tab 3");
        spec3.setIndicator("گیاهان مشابه");
        spec3.setContent(R.id.tab3);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);

    }    
}

logcat消息是:

07-18 08:32:37.402: D/gralloc_goldfish(1068): Emulator without GPU emulation detected.
07-18 08:32:40.272: D/AndroidRuntime(1068): Shutting down VM
07-18 08:32:40.272: W/dalvikvm(1068): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
07-18 08:32:40.344: E/AndroidRuntime(1068): FATAL EXCEPTION: main
07-18 08:32:40.344: E/AndroidRuntime(1068): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.AdMd.Plant/com.AdMd.Plant.Tabs}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.os.Looper.loop(Looper.java:137)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at java.lang.reflect.Method.invoke(Method.java:511)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at dalvik.system.NativeStart.main(Native Method)
07-18 08:32:40.344: E/AndroidRuntime(1068): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.widget.TabHost.setCurrentTab(TabHost.java:346)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.widget.TabHost.addTab(TabHost.java:236)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at com.AdMd.Plant.Tabs.onCreate(Tabs.java:32)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.Activity.performCreate(Activity.java:4465)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 08:32:40.344: E/AndroidRuntime(1068):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 08:32:40.344: E/AndroidRuntime(1068):     ... 11 more

正如你在logcat中看到的,它告诉我有一个活动组,但是当我使用它时,该程序有一些警告,它再也无法工作了!

警告是:

1.The method onCreate(Bundle) from the type ActivityGroup is deprecated
2.The type ActivityGroup is deprecated

我应该怎么做? 感谢..

1 个答案:

答案 0 :(得分:0)

您必须为每个标签

提供操作

试试这段代码

public class Tabs extends TabActivity  {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().hide();
    setContentView(R.layout.tabs);
    TabHost tabHost=(TabHost)findViewById(R.id.tabHost);


    TabSpec spec1=tabHost.newTabSpec("Tab 1");

    spec1.setIndicator("اطلاعات گیاه");
    spec1.setContent(new Intent(this,GalleryDemoActivity.class));

    TabSpec spec2=tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("گالری تصاویر");
spec2.setContent(new Intent(this,GalleryDemoActivity.class));


    TabSpec spec3=tabHost.newTabSpec("Tab 3");
    spec3.setIndicator("گیاهان مشابه");
    spec3.setContent(new Intent(this,GalleryDemoActivity.class));

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
}    

}