2017-01-09 1 views
-2

У меня самая неприятная проблема с новой деятельностью. Я создал его в «нормальный» способ:Почему я получаю это «Вам нужно использовать тему Theme.PpCompat (или потомок) с этой« ошибкой »?

Right-Click -> New -> Activity -> Empty Activity 

Однако я получаю эту досадную ошибку, когда я пытаюсь запустить деятельность:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 

Я чувствую, что мой вопрос отличается от других на StackOverflow потому что я уже несколько раз заглядывал в StackOverflow, а также в googling в целом, но эти ошибки появляются, когда кто-то пытается открыть диалоговое окно, а не когда они просто пытаются запустить новую активность.

Вот моя активность Класс ViewAllStudents.java:

public class ViewAllStudents extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_view_all_students); 
    } 
} 

Я получаю ошибку на setContentView(R.layout.activity_view_all_students); линии.

Мой макет файл ресурсов activity_view_all_students.xml:

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

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

    <ListView 
     android:id="@+id/student_row" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 

Мои включаемый файл student_table_header.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:background="@color/DARKOLIVEGREEN" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <TextView 
     android:id="@+id/student_number_header" 
     style="@style/StdTableHeader" 
     android:layout_weight="1" 
     android:text="@string/student_number_header"/> 

    <TextView 
     android:id="@+id/student_id_header" 
     style="@style/StdTableHeader" 
     android:text="@string/student_id_header"/> 

    <TextView 
     android:id="@+id/student_location_header" 
     style="@style/StdTableHeader" 
     android:text="@string/student_location_header"/> 

    <TextView 
     android:id="@+id/student_status_header" 
     style="@style/StdTableHeader" 
     android:text="@string/student_status_header"/> 

    <TextView 
     android:id="@+id/student_delete_header" 
     style="@style/StdTableHeader" 
     android:text="@string/student_injuries_header"/> 

    <TextView 
     android:id="@+id/student_deleted_header" 
     style="@style/StdTableHeader" 
     android:text="@string/student_deleted_header"/> 

    <TextView 
     android:id="@+id/student_last_modified" 
     style="@style/StdTableHeader" 
     android:text="@string/student_last_modified_header"/> 

</LinearLayout> 

Наконец, мои стили файлов ресурсов styles.xml:

<resources> 
    <style name="StdTableHeader"> 
     <item name="android:textSize">14sp</item> 
     <item name="android:paddingLeft">4dp</item> 
     <item name="android:paddingRight">4dp</item> 
     <item name="android:paddingTop">2dp</item> 
     <item name="android:paddingBottom">2dp</item> 
     <item name="android:layout_weight">10</item> 
     <item name="android:layout_width">0dp</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:textColor">@color/WHITE</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textAllCaps">true</item> 
     <item name="android:gravity">center</item> 
    </style> 
</resources> 

Мой AndroidManifest.xml

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/app_icon" 
     android:label="@string/app_name" 
     android:supportsRtl="true"> 
     <activity 
      android:name=".main.MainActivity" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="adjustPan|stateHidden"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".forms.formOne" 
      android:label="@string/form_one_header" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="adjustPan|stateHidden" /> 
     <activity 
      android:name=".forms.formTwo" 
      android:label="@string/form_two_header" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="adjustPan|stateHidden" /> 
     <activity 
      android:name=".forms.formThree" 
      android:label="@string/form_three_header" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="adjustPan|stateHidden" /> 
     <activity 
      android:name=".main.AddStudent" 
      android:label="@string/title_activity_add_patient" 
      android:theme="@style/AppTheme.NoActionBar" /> 

     <activity android:name=".main.ViewAllStudents"></activity> 
    </application> 

</manifest> 
+1

hint: 'extends AppCompatActivity' –

+0

Возможный дубликат [вам нужно использовать тему Theme.PpCompat (или потомок) с этим действием] (http: // stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity) – mlg

+0

'Вам нужно использовать тему Theme.AppCompat (или потомок) с этим действием Сделайте это. –

ответ

0

Хорошо ... чтобы сделать длинный ответ коротким, проверьте файлы AndroidManifest.xml. По какой-то причине, AndroidStudio пренебрегали вставить критическую линию:

android:theme="@style/AppTheme.NoActionBar" 

AndroidStudio вставил эту строку для всех моих других видов деятельности, которые я создал для этого, кроме одного.

Спасибо всем, кто нашел время, чтобы помочь, и кто терпел мое невежество.

1

Добавить этот атрибут

android:theme="@style/Theme.AppCompat.Light" 

в теге деятельности.

Или есть styles.xml вроде следующего

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

</resources> 

и в явном оных этого атрибута

android:theme="@style/AppTheme" 

в теге приложений.

+0

Ни у кого из моих трех других действий нет, и все они работают. – Brian

+0

вы использовали MainActivity extends AppcompactActivity, поэтому вы должны использовать это –

+0

@ Брайан. У вашей другой активности есть «AppTheme», которая, как оказалось, расширяет «Theme.AppCompat». Таким образом, ваши другие действия не сбой. –

Смежные вопросы

 Смежные вопросы