1

I'm following Google's tutorial on Android app development using Android Studio (I'm using 2.1.3), and I'm following the instructions, however, I have been unable to run my basic app without it crashing immediately. Android Studio's Android Monitor outputs the following:

FATAL EXCEPTION: main
Process: com.example.myfirstapp, PID: 2384
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

What am I doing wrong? What theme should I use, and what code should I edit? For the record, I am outputting to a Nexus 5 both physically and emulator, and to Android API 23.

Taie
  • 1,021
  • 16
  • 29
  • 1
    This may help: http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – Paresh P. Sep 02 '16 at 17:52
  • Can you post the `themes.xml` where you define your theme? It's in `res/values/themes.xml` and should look something like ` – fattire Sep 02 '16 at 18:12
  • My `styles.xml` is as follows ` ` – user6788715 Sep 05 '16 at 17:13
  • Try to change the theme of the activity such as HoloDark or HoloLight etc. I have also faced the same problem, but after changing the theme, the error didnot revoke. – Sampad Sep 12 '16 at 05:05

2 Answers2

0

In your Manifest, below permissions, inside activity tag, put/change attribute android:theme="@style/Theme.AppCompat"

Or if you want to customize your theme change it to android:theme="@style/MyTheme" And add new resource file inside res/values and name it "styles" (styles.xml) and use it as :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="Theme.AppCompat">
    // customize your theme here...(optional)
    </style>
</resources>
user6657161
  • 361
  • 1
  • 8
  • I edited my `AndroidManifest.xml` to include `android:theme="@style/Theme.AppCompat"` in the `` tag but that didn't work. Where should I put `android:theme="@style/Theme.AppCompat"`? – user6788715 Sep 04 '16 at 10:06
  • Brother, your manifest must have a theme already, you just need to spot it. You do not have to add it. You need to change it. – user6657161 Sep 04 '16 at 13:46
  • The theme is there, I did replace it with `android:theme="@style/Theme.AppCompat"`, and I still get the error readout `java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.` – user6788715 Sep 05 '16 at 17:08
  • Try second method using styles file. File name styles contains s while in code its style only. – user6657161 Sep 05 '16 at 17:10
0

Try to change the package name at the top the MainActivity.java to resemble the root directory of your app.

That said, the next this you will have to do is add the following import statement to thesame file.

import android.support.v7.app.AppCompatActivity;

Then you rebuild and run the app again.