Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

android - Unfortunately, (App Name) has stopped when i use fragment to use Google Maps

Can anyone clarify where my error is? The Android app crashes with the error, "Unfortunately, my app has stopped working".Just when put fragment in Main_layout file.

<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"
tools:context=".MainActivity" >

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

And here is some of Manifest file

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

All of the permissions are exist in my Manifest file , and I've extended FragmentActivity in java class

Please help me to solve this problem

LogCat: 04-10 23:01:51.963: I/dalvikvm(10356): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzg 04-10 23:01:51.963: W/dalvikvm(10356): VFY: unable to resolve virtual method 369: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller; 04-10 23:01:51.963: D/dalvikvm(10356): VFY: replacing opcode 0x6e at 0x000b 04-10 23:01:51.963: D/AndroidRuntime(10356): Shutting down VM 04-10 23:01:51.963: W/dalvikvm(10356): threadid=1: thread exiting with uncaught exception (group=0x41907d88) 04-10 23:01:51.983: E/AndroidRuntime(10356): FATAL EXCEPTION: main 04-10 23:01:51.983: E/AndroidRuntime(10356): Process: com.example.myapp, PID: 10356 04-10 23:01:51.983: E/AndroidRuntime(10356): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread.access$800(ActivityThread.java:144) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.os.Handler.dispatchMessage(Handler.java:102) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.os.Looper.loop(Looper.java:212) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread.main(ActivityThread.java:5135) 04-10 23:01:51.983: E/AndroidRuntime(10356): at java.lang.reflect.Method.invokeNative(Native Method) 04-10 23:01:51.983: E/AndroidRuntime(10356): at java.lang.reflect.Method.invoke(Method.java:515) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 04-10 23:01:51.983: E/AndroidRuntime(10356): at dalvik.system.NativeStart.main(Native Method) 04-10 23:01:51.983: E/AndroidRuntime(10356): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.Activity.setContentView(Activity.java:1929) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.example.myapp.MainActivity.onCreate(MainActivity.java:23) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.Activity.performCreate(Activity.java:5231) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201) 04-10 23:01:51.983: E/AndroidRuntime(10356): ... 11 more 04-10 23:01:51.983: E/AndroidRuntime(10356): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 7095000 but found 0. You must have the following declaration within the element: 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.internal.zzx.zzad(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.internal.zzx.zzac(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.SupportMapFragment$zzb.zzqs(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.dynamic.zza.zza(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.dynamic.zza.onInflate(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279) 04-10 23:01:51.983: E/AndroidRuntime(10356): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 04-10 23:01:51.983: E/AndroidRuntime(10356): ... 21 more 04-10 23:01:54.903: I/Process(10356): Sending signal. PID: 10356 SIG: 9

And this is the manifest file

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Maps API needs OpenGL ES 2.0. -->
<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" >

    <!-- You must insert your own Google Maps for Android API v2 key in here. -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyA--------------------ZQjV4U" />

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

    <activity
        android:name="com.example.myapp.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>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like an error lies in your manifest - Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 7095000 but found 0

I cannot see the content of your manifest file, but my first guess is that you didn't set up Google Play services version or google maps api key meta-data in manifest properly. Everything is explained there: https://developers.google.com/maps/documentation/android/start#add_a_map just like @Daniel Nugent mentioned.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...