24

I am making an app which uses google maps. But in my xml I get th error "Failed to find style 'mapViewStyle' in current theme." Instead I have given onternet permission and used the google maps library inside the application tag.

Can anybody help me over this.

Thanks a lot

following is my xml file...

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
  <com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0ACHOtlugQlOP_-siR3LLyIBjv1SwpKWimIY8jw" />
</Relativelayout>
5
  • show your errored xml file where you get error of style "mapViewStyle".
    – user370305
    Sep 10, 2011 at 10:50
  • 1
    I have edited my post. Have a look at the code.
    – ekjyot
    Sep 10, 2011 at 11:06
  • Where exactly do you get that error message? Sep 10, 2011 at 11:09
  • Is that the whole xml code? If not then please paste the complete code...if it is, then where is your mapview tag? Example of a map app xml file: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.google.android.maps.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="your_api_key_here" android:clickable="true" /> </RelativeLayout> In place of the your_api_key_here, paste your unique google
    – Urban
    Sep 10, 2011 at 19:47
  • This maybe helpful to some. Mar 28, 2018 at 5:38

11 Answers 11

24

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme 

Anything from the above list it may be,

The ultimate reason is ,

We have selected the unavailable Theme for the layout.

This may cause because of,

  1. The selected theme is not available in themes.xml file.
  2. The selected theme is belongs to higher version sdk, but our current target sdk is lower one.

This problem mostly happens,

  1. when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

The Solutions for this problem are,

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  1. So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  2. If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  3. If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

3
  • 1
    Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead.
    – Kev
    Mar 14, 2013 at 20:22
  • Thanks @Kev. I did this when i was new to here... After posted dis i realized and i won't do it again... Thanks for ur concern in warning me... Mar 15, 2013 at 7:49
  • Yeah, I changed my app theme name and was still referencing the old one in the designer view of eclipse. Good advice! Jul 24, 2014 at 16:00
2

Not sure why, but if you add an explicit style and define that in /values/styles.xml this error will go away.

styles.xml:

<style name="mapView">
    <item name="android:gravity">center</item>
</style>

and the layout:

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="YOUR_API_KEY"
    android:visibility="visible"
    style="@style/mapView"
/>

Seems like com.google.android.maps.MapView really wants a style of some sort to be declared.

2

Another reason for these errors might actually be an internal eclipse error.

In that case what does solve it is:

  1. closing the xml layout file
  2. restarting eclipse (or even ADT as I heard it happens there as well)

It usually is worth a try (esp. when you encounter this error "out of the blue"), since it does not take a lot of time. Although for the OP it might not be the case, this could still help someone else searching.

1
  • 1
    Closing the xml layout file fixed this for me. Thank you! Feb 26, 2015 at 2:30
1

You need to change only Android 2.2 to android 3.0, and also give id and user-permissions and child of application

1

Every android theme is not suitable for every type of view. Because of this we should select one of the suitable themes for our view type.

Here is how problems looks
If theme is not suitable it will give us missing styles error.

enter image description here

Here is the solution
1.Firstly select theme bar.
enter image description here

2.Select theme for your view

enter image description here

3.After selecting theme then press ok.
If the theme is suitable for your view it will render if not then select another theme and try until you find a suitable theme for your application.
Whenever your theme is suitable it will render as like the picure below. enter image description here

0

If you are using Android 3.0 and above on your Graphical Layout. Try changing it to Android 2.2 or 2.3.

0

This error happens due to the fact that some icons or property are missing for mapViewStyle. If you have ever applied any custom theme on android device then you might have faced error like "missing assets" or "theme improperly compiled" etc. These error arises due to lack for icons or layout for each and every look of phone such as button, menus, status bar etc.

Similar is the case with the mapViewStyle. During the project creation you might have selected a default theme for your application. This theme is missing certain components for mapViewStyle such button icon or style (Just giving the idea, I don't know if this is true or not). I think you might have understood the point.

Now to remove the error go into res>values>styles.xml

remove the previous theme line and put this one

<style name="AppBaseTheme" parent="android:Theme.Light">

The above example is just for making you understand and give you a broad idea of the problem. I don't state that it's 100% true.

if this answer is useful then mark it as useful.

0

Make sure you have added your custom theme part in all other styles.xml present under different values folder under res.

I had similar problem. In my case I had added a custom theme in values-large folder under res. And it was working at runtime but giving error as yours in eclipse. So i tried adding the custom part(in my case totally there was 3 tags added to styles.xml file) in all other styles.xml file. i.e. styles.xml files under values-normal-hdpi, values-normal-mdpi, valuse-v11 and values-v14... And BOOM!!! It solved my problem which wasted my whole day.

0

Make sure your all other styles.xml present under different values contains your custom theme part.

I had similar problem.

In my case I had added a custom theme in values-large folder under res. And it was working at runtime but giving error as yours in eclipse.

So i tried adding the custom part(in my case totally there was 3 tags added to styles.xml file) in all other styles.xml file. i.e. styles.xml files under values-normal-hdpi, values-normal-mdpi, valuse-v11 and values-v14...

And BOOM!!! It solved my problem which wasted my whole day.

0

While I'm sure this won't work for everyone, but for me I simply changed the Theme in the Preview Window to Theme.AppCompat.Light.

Theme Drop-down Circled in Red

It seems the in some cases merely setting the correct theme is the solution. Which theme out of all those choices? Go for the compatibility themes first; after that, good luck!

0

Refresh the xml layout by click Refresh button on Preview or close the xml then open it again fix my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.