Невозможно решить эту ошибку

Я получаю сообщение об ошибке "Вы должны указать способ создания индикатора вкладки" (согласно 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>

Я не могу угадать точную проблему. Был бы благодарен за любое руководство.

1 ответ

Решение

Раскомментируйте эти строки:

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

И использовать только текст, без значков.

  • photospec.setIndicator("Photos")
  • songspec.setIndicator("Songs")
Другие вопросы по тегам