2015-06-05 120 views
0

我得到「您必須指定一種方法來創建選項卡指示器」錯誤(按照logcat)。找不到原因。無法解決錯誤

主要類:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pes.user.pesce/com.pes.user.pesce.MessagesActivity}: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator. 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5257) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator. 

MesaageActivty.java

 public class MessagesActivity extends TabActivity { 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.messages_layout); 

     TabHost tabHost = getTabHost(); 

     // Tab for Photos 
     TabHost.TabSpec photospec = tabHost.newTabSpec("Overview"); 
     // setting Title and Icon for the Tab 
     // photospec.setIndicator("Photos",  getResources().getDrawable(R.drawable.icon_photos_tab)); 
     Intent photosIntent = new Intent(this, AdmissionActivity.class); 
     photospec.setContent(photosIntent); 

     // Tab for Songs 
     TabHost.TabSpec songspec = tabHost.newTabSpec("How to Apply"); 
     // songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab)); 
     Intent songsIntent = new Intent(this, OverviewActivity.class); 
     songspec.setContent(songsIntent); 

     // Adding all TabSpec to TabHost 
     tabHost.addTab(photospec); // Adding photos tab 
     tabHost.addTab(songspec); // Adding songs tab 

    } 

} 

message_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#f8f9fe" 
    android:orientation="vertical" > 

    <include layout="@layout/actionbar_layout" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="15dip" 
      android:text="Admissions" 
      android:textColor="#ff29549f" 
      android:textSize="25dip" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <TabHost 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabhost"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"></TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <!-- <LinearLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 

        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/tab1" 
         android:id="@+id/textView2" /> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="@string/tab2" 
        android:orientation="vertical"></LinearLayout>--> 

       </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 

的manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.pes.user.pesce" > 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".AndroidDashboardDesignActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

       <activity android:name=".AdmissionActivity"></activity> 

     <activity android:name=".OverviewActivity"></activity> 


    </application> 

</manifest> 

我無法猜測確切的問題。將不勝感激任何指導。

+0

嘗試使用只有'則tabspec songspec = tabHost.newTabSpec( 「如何申請」);'取代'TabHost.TabSpec = tabHost.newTabSpec(「如何申請「);' –

+0

如果他/她有很好的進口,它是一樣的@BidhanA – Aspicas

+0

爲什麼你評論了'photospec.setIndicator(」Photos「,......'和'songspec.setIndicator(」Songs「 ,.......' – Aspicas

回答

1

取消註釋行:

  • photospec.setIndicator("Photos", ......
  • songspec.setIndicator("Songs", .......

而且使用onlky文本,不帶圖標。

  • photospec.setIndicator("Photos")
  • songspec.setIndicator("Songs")