167

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style mapViewStyle in current theme.

I tried every solutions available to solve this problem but nothing seems to work. I have included library in the manifest file. I even created style is styles.xml, I have chosen Google Apis build target as well.

Can somebody please give me a solution?

here is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/AppTheme"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >


 <com.google.android.maps.MapView
     android:id="@+id/themap"
     style="@style/mapViewStyle"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:apiKey="here i have my key"
     android:clickable="true"
     android:enabled="true" />

  </RelativeLayout>   

Here is my manifest snippet:

  <uses-library android:name="com.google.android.maps" />

    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Second" />

    <activity android:name=".Third"  android:theme="@android:style/Theme.Black"/>
  </application>

here is my style.xml file

<resources>
    <style name="mapViewStyle" parent="@android:style/Theme.Black">
    </style>
</resources>
vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • Sure it's not `@style/AppTheme` your missing? – Blundell Nov 18 '12 at 12:29
  • Thank you for your response, I m new to Android development. It didn't solve the problem. I added AppTheme but I'm still getting the same error. I changed the whole application's theme to Theme.Light so that there won't be any more conflicts. But the problem still persists!!! I can't figure out how to overcome this problem. –  Nov 18 '12 at 13:12
  • When I run the application, it runs fine til the second activity but in the activity which displays maps, it displays "Unfortunately yourapp has stopped" –  Nov 18 '12 at 13:14
  • @DebeshAdhikari If your problem is solved, consider accepting the answer which helped you solve it – Sachin Jain Nov 18 '15 at 13:12
  • Changing `minSDKVersion` and `targetSdkVersion` in `build.gradle` file worked for me. – rupinderjeet Jun 01 '16 at 10:52
  • This issue happens sometimes you create too many projects. And I try everything I can do, it doesn't work. Finally I just restart my Android Studio, you know what, it works normally! – DysaniazzZ Aug 03 '16 at 14:56

21 Answers21

155

For Android Studio (or IntelliJ IDEA),

If everything looks OK in your project and you're still receiving the error in your layouts, try to 'Invalidate caches & restart'.

Enjoy a coffee while Android Studio is recreating caches & indexes.

how to invalidate cache & restart

gbero
  • 3,890
  • 1
  • 26
  • 30
154

I had the same problem and found it was the Theme dropdown at the top of the graphical layout editor. I changed from Holo to Theme and the layout displayed and error disappeared.

Benno
  • 2,534
  • 1
  • 17
  • 27
14

What I usually do is the following: a Gradle Clean, Rebuild and Sync all my Gradle files. After that I restart Android Studio, and I go to:

Select Theme -> Project Themes -> AppTheme
Henry Zhu
  • 2,488
  • 9
  • 43
  • 87
13

This is because you select not a theme of your project. Try to do next:

enter image description here

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
8

If we are creating too many projects using Android Studio sometime Rendering issue comes. Even creating a blank activity we receive such rendering error. Please shut down and restart Android studio. In case the issue persists you can Android Studio Cache Invalidation and Restart

Hope this helps. It works similar fashion as rule of thumb, in case all looks good and still error persists a restart of application usually resolves the issue.

Doogle
  • 1,236
  • 1
  • 17
  • 17
4

In my case the problem occurred while the default setting for Android Version in the Designer was set to 'Preview N'. Changed Android Version to '23' and the error notification went away.
Edit
And don't forget to uncheck 'Automatically Pick Best'.

redocoder
  • 201
  • 2
  • 9
2

I had the same problem using Android Studio 1.5.1.

This was solved by using the Android SDK Manager and updating Android Support Library, as well as Local Maven repository for Support Libraries.

enter image description here

After updating the SDK and restarting Android Studio, the problem was rectified.

Hope this helps anyone who has the same problem after trying other suggestions.

keshav.bahadoor
  • 1,886
  • 1
  • 13
  • 19
  • I didn't try any of the other suggestion, went right to this one and my preview rendered without errors after updating SDK then restarting Android Studio. – xpagesbeast Oct 19 '16 at 02:25
2

I solved it by changing "classpath" in "dependencies" in build.gradles.

Just change:

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0-alpha2'

or something like that to:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
Pang
  • 9,564
  • 146
  • 81
  • 122
1

I got this error after overriding action bar style like this. Also i lost action bar in preview.

<style name="general_app_theme" parent="@style/Theme.AppCompat">
    <!-- for API level 11 -->
    <item name="android:actionBarStyle">@style/action_bar_style</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/action_bar_style</item>

</style>

<style name="action_bar_style" parent="@style/Widget.AppCompat.ActionBar">
    <!-- for API level 11 -->
    <item name="android:height">@dimen/action_bar_height</item>
    <item name="android:background">@color/action_bar_color</item>
    <item name="android:displayOptions">showTitle</item>

    <!-- Support library compatibility -->
    <item name="displayOptions">showTitle</item>
</style>

So, problem is overriding theme by my custom. this is the reason, why I've changed AppCompat (from "Project Themes") to general_app_theme (from "Manifest Themes"). Now I have no this error and action bar in preview come back.

1

Try switching the theme in the design view to one of the options in "Manifest Themes". I'm guessing this is Because you are inheriting the theme from the manifest to support multiple api levels. It worked for me anyway.

Setheck
  • 19
  • 1
  • 1
1

With reference to the answer provided by @Benno: Instead of changing to a specific theme, you can simply choose 'DeviceDefault' from the theme menu. This should choose the theme most compatible with the emulated device.

1

If you still have the problem after trying all the solutions above, please try modify the API Level as shown below. Incorrect API Level may also cause the problem.

enter image description here

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
xelmirage
  • 61
  • 2
1

I got the same problem with my customized theme that used Holo.Light as its parent. In grayed text Android Studio indicated that some attributes were missing. When I added these missing attributes as follows, the rendering problems went away -

    <item name="android:textEditSuggestionItemLayout"></item>
    <item name="android:textEditSuggestionContainerLayout"></item>
    <item name="android:textEditSuggestionHighlightStyle"></item>

Even though they introduced errors in my style's theme, they caused no problems in rendering the activity designs or building my app.

Earl Allen
  • 29
  • 5
  • 1
    I spoke too soon - the screens rendered okay; however, I am getting 'No resource found' for the Container and Style lines'. Stay tuned. – Earl Allen Jun 13 '16 at 20:03
  • Evidently the parent theme of android.'theme.Holo.Light' is missing these attributes and there is no documentation I can find to include them. I solved my problem by switching to the 'android.theme.Holo' theme. – Earl Allen Jun 13 '16 at 20:39
1

It can be fixed by changing your theme in styles.xml from Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar

<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>

to

<style name="AppTheme" parent="Base.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>

and clean the project. It will surely help.

Mrigank
  • 522
  • 4
  • 13
0

Most of the errors in XML happen due to the names you have given to the resources.

Images stored in the drawable folder need to be named in a proper manner. just check these things:

  1. Are there any duplicate files? if so remove the duplicates. (For example "image.jpg" and "image.png" are not allowed in the same time. It will not show any errors but sometimes it will show that R.java cannot be resolved)
  2. Do the filenames contains any uppercase letters? If so right click on that file->refactor->rename and rename it with all lowercase, no hyphens, and only a-z and 0-9 are allowed.

Just make sure of the above cases.

Aurora
  • 4,384
  • 3
  • 34
  • 44
Eldhose
  • 163
  • 2
  • 4
0

You can simply remove this error through change "App theme" and select any theme such as light. This error will be removed.

tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
0

I meet the same problem.Select theme to another one in preview can solve problem temporary.Like the image

Finally,I found out that there are AppTheme and AppBaseTheme in my styles.xml. And AppTheme has parent AppBaseTheme. The AppBaseTheme has parent of one system style.

And every layout file use the theme AppTheme. Just change AppTheme's parent to AppBaseTheme's parent. It solve the problem permanent.

Cui Qing
  • 157
  • 2
  • 5
0

Just need click button 'AppTheme', and choose 'Manifest Themes'. It works in most cases.

nicolas asinovich
  • 3,201
  • 3
  • 27
  • 37
0

For me, it was occurring on menu.xml file as i was using android:Theme.Light as my theme, So what i did was -

  1. Added new Folder in res directory named values-v21.

  2. Added android:Theme.Material.Light as AppTheme in styles.xml.

B.shruti
  • 1,589
  • 1
  • 21
  • 41
0

This is very late but i like to share my experience this same issue. i face the same issue in Android studio i tried to some other solution that i found in internet but nothing works for me unless i REBUILD THE PROJECT and it solve my issue.

Hope this will works for you too.

Happy coding.

Humaira Naaz
  • 280
  • 2
  • 12
0

Change your App theme to AppCombat.. enter image description here

nafees ahmed
  • 948
  • 1
  • 12
  • 18