谷歌地图Android API v2给出了“应用程序***已意外停止”错误

时间:2013-06-27 02:02:11

标签: android google-maps-api-2

我正在关注谷歌地图Android API v2设置指南,我在指南中做了所有事情,但事情似乎不起作用,我得到“应用程序mapdemo(进程com.example.mapdemo)意外停止。请尝试再次”。我已经浪费了一整天,仍然无法找到解决方案。 :(

我的清单文件是:

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

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

    <permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

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

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

activity_main.xml中

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

MainActivity.java

package com.example.mapdemo;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

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

LogCat输出是:

06-27 10:58:09.263: D/AndroidRuntime(18097): Shutting down VM
06-27 10:58:09.263: W/dalvikvm(18097): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
06-27 10:58:09.273: E/AndroidRuntime(18097): FATAL EXCEPTION: main
06-27 10:58:09.273: E/AndroidRuntime(18097): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapdemo/com.example.mapdemo.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread.access$1500(ActivityThread.java:132)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.os.Looper.loop(Looper.java:143)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread.main(ActivityThread.java:4196)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at java.lang.reflect.Method.invokeNative(Native Method)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at java.lang.reflect.Method.invoke(Method.java:507)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at dalvik.system.NativeStart.main(Native Method)
06-27 10:58:09.273: E/AndroidRuntime(18097): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.Activity.setContentView(Activity.java:1702)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:11)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
06-27 10:58:09.273: E/AndroidRuntime(18097):    ... 11 more
06-27 10:58:09.273: E/AndroidRuntime(18097): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.mapdemo-2.apk]
06-27 10:58:09.273: E/AndroidRuntime(18097):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-27 10:58:09.273: E/AndroidRuntime(18097):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-27 10:58:09.273: E/AndroidRuntime(18097):    ... 19 more

错误太令人沮丧了。任何帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

错误表示找不到该类。你添加google-play-services项目(支持libray)的方式似乎存在问题,如果你做的话。结帐:

Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2

Unable instantiate android.gms.maps.MapFragment

java.lang.noclassdeffounderror: com.google.android.gms.R$styleable nothing helped me

他们谈论类似的问题。希望它有所帮助。