2016-09-26 1 views
-1

ERROR_LOG starten:Während Material_Theme Fehler beim Anwenden: Kann Aktivität ComponentInfo

D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hetal13.material_design_demo, PID: 2611 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hetal13.material_design_demo/com.example.hetal13.material_design_demo.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 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:5254) 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.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.example.hetal13.material_design_demo.MainActivity.onCreate(MainActivity.java:13) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  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:5254)  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)  Application terminated.

Style.xml:

<resources> 

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

</resources> 

MainActivity.java:

package com.example.hetal13.material_design_demo; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 



public class MainActivity extends AppCompatActivity { 

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

    } 
} 

activity_main.xml:

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

    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 

    android:orientation="vertical" 
    tools:context="com.example.hetal13.material_design_demo.MainActivity"> 

    <Button 
     android:text="@string/button_submit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/editText" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="46dp" 
     android:id="@+id/button" 
     /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="textPersonName" 
     android:ems="10" 
     android:layout_marginTop="108dp" 
     android:id="@+id/editText" 

     android:textAlignment="center" 
     tools:ignore="LabelFor" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 
</LinearLayout> 

Antwort

0

Sie müssen tun folgende Änderungen in Ihrem Style.xml. (Sie können auch versuchen, diesen Code-Schnipsel kopieren einfügen. Wahrscheinlich sollte es funktionieren.)

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

Alles, was Sie brauchen, ist Theme.AppCompat Thema nach Ihrer logcat.

hoffe, das hilft

+0

Aber was tun, wenn ich Material Design ui – Hetal1311

+0

hinzufügen möchten ** Dieses Material Thema ist nur! ** Nur rückwärtskompatibel. Ich nehme an, du startest gerade android dev, also würde ich dir vorschlagen, einen Blick auf offizielle Google Docs zu werfen, um besser zu verstehen. ** Wir sollten kompatible Themes verwenden, damit Pre-Lollipop-Geräte auch eine gewisse materielle Note erhalten. ** –

+0

Ich empfehle dringend, dass Sie [diesen Link lesen] (https://developer.android.com/training/material/compatibility.html). Überlegen Sie, ob Sie meine Antwort aufheben und akzeptieren, wenn Sie es nützlich finden :) –

Verwandte Themen