3

I'm trying to built map app and following this link step by step. I found similar topics in here but didn't help me. I want to show map, but when I run it, it return force close and my android device. I saw a lots of questions about this error but no one really answer to my problem. Here is my LogCat:

03-21 20:55:57.476: D/AndroidRuntime(4090): Shutting down VM
03-21 20:55:57.476: W/dalvikvm(4090): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 20:55:57.500: E/AndroidRuntime(4090): FATAL EXCEPTION: main
03-21 20:55:57.500: E/AndroidRuntime(4090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapandroid/com.example.mapandroid.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Looper.loop(Looper.java:137)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at dalvik.system.NativeStart.main(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.example.mapandroid.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:67)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Activity.performStart(Activity.java:5173)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 11 more
03-21 20:55:57.500: E/AndroidRuntime(4090): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the  element:     
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 24 more
03-21 20:55:57.515: D/dalvikvm(4090): GC_CONCURRENT freed 233K, 10% free 7615K/8455K, paused 13ms+2ms, total 39ms
03-21 21:36:53.375: W/dalvikvm(4279): VFY: unable to resolve static field 3202 (MapAttrs) in Lcom/google/android/gms/R$styleable;
03-21 21:36:53.375: D/dalvikvm(4279): VFY: replacing opcode 0x62 at 0x000e
03-21 21:36:53.375: D/AndroidRuntime(4279): Shutting down VM
03-21 21:36:53.375: W/dalvikvm(4279): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 21:36:53.382: E/AndroidRuntime(4279): FATAL EXCEPTION: main
03-21 21:36:53.382: E/AndroidRuntime(4279): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.example.map.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:57)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Activity.performStart(Activity.java:5173)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Looper.loop(Looper.java:137)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at dalvik.system.NativeStart.main(Native Method)

and here my MainActivity.java

package com.example.map;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;


public class MainActivity extends FragmentActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

}

here is my activity_main.xml :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.map.MainActivity"
tools:ignore="MergeRootFrame" />

and here is my fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context="com.example.map.MainActivity$PlaceholderFragment" >



<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

and my manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="0123456789abcde" />

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.map.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

I've read step by step from that following link, but its seem many error in my code. What I miss? any suggestion? many thanks.

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
Yohanim
  • 3,319
  • 9
  • 52
  • 92
  • If you have found the answer to this question, please add it as an answer (and only an answer) to this question. There is no need to edit your question to include the answer. – The Guy with The Hat Mar 27 '14 at 15:13

2 Answers2

2

Move this

 <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="0123456789abcde" />

 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

to between your < application>< /application> tag.

Piyush
  • 18,895
  • 5
  • 32
  • 63
  • hi, thanks for your reply, but it doesn't solve my problem. it is right to write `@integer/google_play_services_version` in android values? – Yohanim Mar 21 '14 at 15:08
  • Yes it is. You must check that you have referenced your google play library properly. – Piyush Mar 21 '14 at 15:09
  • Is this 0123456789abcde your api key? – Piyush Mar 21 '14 at 15:12
  • @Raghunandan Ya i know but yet for verification. – Piyush Mar 21 '14 at 15:15
  • @PiYusHGuPtA No, that isn't my API key, I replaced that with api key Google android map v2. What I curious is in tag com.google.android.gms.version, should I changed "@integer/google_play_services_version" to google play services version in version.xml in res/values of library project? – Yohanim Mar 21 '14 at 15:38
  • @CodingHorror i answered that in post. did you read my post and read the docs i linked to?? and why is it bothering you so much?? – Raghunandan Mar 21 '14 at 15:54
1

com.google.android.gms.R$styleable

This is usually due to having not referenced google play services properly

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the element:

You are also missing 2 meta tags as a child of application tag of manifest file

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
 <meta-data
 android:name="com.google.android.maps.v2.API_KEY"
 android:value="your api key"/>
 <meta-data 
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />
 <activity
    android:name="com.example.map.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

it is right to write @integer/google_play_services_version in android values?

Yes. Check the version.xml in your res/values of library project. Will look like below.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">4030500</integer>
</resources>

All you need to do is reference the same as

 android:value="@integer/google_play_services_version" /> 
 // this is what should be in the application tag of manifest file
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • hi, thanks for your reply, but moving meta-data to application tag still not solved my problem. what I miss? did you mean referencing from point number 2,3,4 from this https://blog-emildesign.rhcloud.com/?p=435link ? – Yohanim Mar 21 '14 at 15:14
  • @CodingHorror 1. Have you referenced google play services library project in your android project. 2. Your api key does not look right. 3. Have you enabled maps for android in the api console – Raghunandan Mar 21 '14 at 15:16
  • @CodingHorror and if you want map in a fragment what you are doing is not right. Either extend from `SupportMapFragment` or use `MapVIew`. The blog is old needs to be updated. http://stackoverflow.com/questions/20919048/android-android-view-inflateexception-binary-xml-file-line-8-error-inflatin – Raghunandan Mar 21 '14 at 15:20
  • in my code I just write this : does anything to change? – Yohanim Mar 21 '14 at 15:22
  • @CodingHorror what is the change that your talking?. where do you have that code. Yes it makes a difference coz it is required as a child of applciationt tag as of updated google play services which is rev 15 as of date i guess. Please follow the official docs its updated. https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2 – Raghunandan Mar 21 '14 at 15:23
  • so blogs that I followed its old and cannot to be implemented? – Yohanim Mar 21 '14 at 15:25
  • @CodingHorror what has that gotta do with adt. I suggest you follow https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2 and then start asking questions. yes its old it does not suggest you have to have the other metatag. few permissions are not required – Raghunandan Mar 21 '14 at 15:27
  • Thanks for your reply, and now I followed your link and works perfectly. That's blog seems to old and not to be followed. Many thanks and kind regards. – Yohanim Mar 22 '14 at 06:29
  • can you see this http://stackoverflow.com/questions/22576049/gallery-has-stopped-while-cropping-image-in-kitkat-nexus7 – Piyush Mar 22 '14 at 10:06