标签活动无效

时间:2013-10-28 07:58:20

标签: android tabs

您好我已经创建了一个简单的标签活动,但它无法正常工作,我需要一些帮助,我知道我在某处做了一些愚蠢的错误..请帮助那些人.. 给我的logcat下面

10-28 03:44:22.772: E/AndroidRuntime(1119): java.lang.RuntimeException: Unable to start                       
activity ComponentInfo{com.friendfinder/com.friendfinder.TabActivityLayouts}: 
java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.

10-28 03:44:22.772: E/AndroidRuntime(1119):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)

10-28 03:44:22.772: E/AndroidRuntime(1119):     at 
android.app.ActivityThread.access$600(ActivityThread.java:141)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at  
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
 android.os.Handler.dispatchMessage(Handler.java:99)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
  android.os.Looper.loop(Looper.java:137)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
  android.app.ActivityThread.main(ActivityThread.java:5103)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
  java.lang.reflect.Method.invokeNative(Native Method)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
  java.lang.reflect.Method.invoke(Method.java:525)

 10-28 03:44:22.772: E/AndroidRuntime(1119):    at 
   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)

在下方提供我的标签活动课程。

            public class TabActivityLayouts extends TabActivity{


        @Override   
         protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.welcome_form);

    TabHost tabhost= getTabHost();

    TabSpec spec=tabhost.newTabSpec("Welcome");     
    spec.setIndicator("w", getResources().getDrawable(R.drawable.new_tab1));
    Intent in=new Intent(this,WelcomeTabActivity.class);
    spec.setContent(in);

    TabSpec specific=tabhost.newTabSpec("Friends");
    spec.setIndicator("s", getResources().getDrawable(R.drawable.new_tab2));
    Intent i=new Intent(this,FriendsListTabActivity.class);
    spec.setContent(i);

    tabhost.addTab(spec);
    tabhost.addTab(specific);
         }

                }

1 个答案:

答案 0 :(得分:0)

第二个标签中的错误,您错误地将指标实例设置为specific而不是最后一个标签中的spec

而不是如下:

TabSpec specific=tabhost.newTabSpec("Friends");
spec.setIndicator("s", getResources().getDrawable(R.drawable.new_tab2)); //Change the instance here.
Intent i=new Intent(this,FriendsListTabActivity.class);
spec.setContent(i);

执行以下操作:

TabSpec specific=tabhost.newTabSpec("Friends");
specific.setIndicator("s", getResources().getDrawable(R.drawable.new_tab2));
 Intent i=new Intent(this,FriendsListTabActivity.class);
specific.setContent(i);