1

I have followed an instruction on youtube to create a map/location application. My first step is only to show the map but I get stuck because of "Unfortunately, MyLocApp has stopped". My codes are followed. What have I been doing wrong?

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android":
        package="tri.mylocapp"
        android:versionCode="1"
        android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="14" />
    <permission 
        android:name="tri.mylocapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"
       />
    <uses-permission android:name="tri.mylocapp.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission      android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
    <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"/>


    <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="AIzaSyDZIavpm2Kcj4QXnb01qxoZqiEXTBXTABw"/>
        <activity
        android:name="tri.mylocapp.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>

This is the layout xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

This is the proguard-project.txt:

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

This is the MainActivity.java:

package tri.mylocapp;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

LogCat:

 D/AndroidRuntime(639): Shutting down VM
 W/dalvikvm(639): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
 E/AndroidRuntime(639): FATAL EXCEPTION: main
 E/AndroidRuntime(639): java.lang.RuntimeException: Unable to start activity ComponentInfo{tri.mylocapp/tri.mylocapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
 E/AndroidRuntime(639):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
 E/AndroidRuntime(639):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
 E/AndroidRuntime(639):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
 E/AndroidRuntime(639):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
 E/AndroidRuntime(639):     at android.os.Handler.dispatchMessage(Handler.java:99)
 E/AndroidRuntime(639):     at android.os.Looper.loop(Looper.java:137)
 E/AndroidRuntime(639):     at android.app.ActivityThread.main(ActivityThread.java:4340)
 E/AndroidRuntime(639):     at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(639):     at java.lang.reflect.Method.invoke(Method.java:511)
 E/AndroidRuntime(639):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
 E/AndroidRuntime(639):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 E/AndroidRuntime(639):     at dalvik.system.NativeStart.main(Native Method)
 E/AndroidRuntime(639): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
 E/AndroidRuntime(639):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
 E/AndroidRuntime(639):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
 E/AndroidRuntime(639):     at android.app.Activity.setContentView(Activity.java:1835)
 E/AndroidRuntime(639):     at tri.mylocapp.MainActivity.onCreate(MainActivity.java:10)
 E/AndroidRuntime(639):     at android.app.Activity.performCreate(Activity.java:4465)
 E/AndroidRuntime(639):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
 E/AndroidRuntime(639):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
 E/AndroidRuntime(639):     ... 11 more
 E/AndroidRuntime(639): 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 <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  E/AndroidRuntime(639):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.dynamic.a.a(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
 E/AndroidRuntime(639):     at android.app.Activity.onCreateView(Activity.java:4242)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
 E/AndroidRuntime(639):     ... 20 more
 I/Process(639): Sending signal. PID: 639 SIG: 9
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • possible duplicate of [After Google Play Service update to version 13 I got an error](http://stackoverflow.com/questions/19723811/after-google-play-service-update-to-version-13-i-got-an-error) – laalto Mar 20 '14 at 07:47

2 Answers2

1

Your logcat clearly said

.818: E/AndroidRuntime(639): 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 <application> element:        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
 03-20 17:11:43.818:icesUtil.isGooglePlayServicesAvailable(Unknown 

Add the Google Play services version to your app's manifest

Edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.

You need to add <meta-data> under <application> tag into your AndroidManifest.xml

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

This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml

build your manifest.xml like:

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

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

 </application>
M D
  • 47,665
  • 9
  • 93
  • 114
  • The codes do solve my problem, 'has stopped' is solved, thank you. However, my app starts but it doesn't not show the maps (it does show the map's screen but no content). Anyway, I will post another question for this. – Tri Quoc Nguyen Mar 20 '14 at 12:36
0

Change locap to locapp in the declaration of your activity in the manifest

k3v1n4ud3
  • 2,904
  • 1
  • 15
  • 19