0

I am trying to run my app in my android device but unfortunately i can't. My logcat :

> Process: com.android.app.myapplication, PID: 15138
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.app.myapplication/com.android.app.myapplication.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.    
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)           
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)         
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
> 
--->Caused by: java.lang.IllegalStateException: You need to use a
> Theme.AppCompat theme (or descendant) with this activity. at
> android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
> at
> android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
> at
> android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
> at
> com.android.app.myapplication.MainActivity.onCreate(MainActivity.java:13)
> at android.app.Activity.performCreate(Activity.java:5248) at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
> at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
> at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
> at android.app.ActivityThread.access$800(ActivityThread.java:139) at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
> at android.os.Handler.dispatchMessage(Handler.java:102) at
> android.os.Looper.loop(Looper.java:136) at
> android.app.ActivityThread.main(ActivityThread.java:5086) at
> java.lang.reflect.Method.invokeNative(Native Method) at
> java.lang.reflect.Method.invoke(Method.java:515) at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at
> de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) at
> dalvik.system.NativeStart.main(Native Method)

I believe it has something to do with the manifest, API, Gradle Scripts or something because my activities and layouts do not have errors.

We're All Mad Here
  • 1,544
  • 3
  • 18
  • 46
  • 2
    Is it perhaps because it is asking:You need to use a Theme.AppCompat theme (or descendant) with this activity, and therefore i got to follow this post: http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – We're All Mad Here Jul 06 '15 at 23:50
  • 1
    Oh, if only people would read their own stack traces before they ask questions on stackoverflow. – Christine Jul 06 '15 at 23:51
  • This is a well know issue documented in many questions here in the stack. Your problem is that your application theme does not descend from Theme.AppCompat - your activity is probably extending AppCompatActivity. You can either extend an Activity instead or change your theme hirarchy. – E. Fernandes Jul 06 '15 at 23:52
  • I did change my theme in my manifest as suggested ---android:theme="@style/Theme.AppCompat.Light"--- but it did not work – We're All Mad Here Jul 06 '15 at 23:59

3 Answers3

1

Check out You need to use a Theme.AppCompat theme (or descendant) with this activity. Likely your activity is extending the incorrect superclass.

Community
  • 1
  • 1
Jan K
  • 365
  • 1
  • 14
0

Go to file Manifests and change the theme.

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/Tema" > <------ Change here (You can put Theme.AppCompat or others from that
Jean Carlos
  • 1,613
  • 3
  • 18
  • 26
0

Make sure your activity extends appacompact activity

public class BaseActivity extends AppCompatActivity {

...
}

and your style.xml needs a version of Theme.AppCompact

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">

  </style>

finally make sure the application class in your manifest points to that style

 <application
    android:theme="@style/AppTheme">
Brian
  • 4,328
  • 13
  • 58
  • 103