Android Google Maps v2:ClassNotFoundExeption:com.google.android.gms.maps.MapFragment

时间:2013-11-08 21:03:54

标签: android google-maps google-maps-android-api-2

对我不好的英语抱歉。

我的示例地图活动有问题。我想我看到了关于这个问题的成千上万的话题,但没有一个能解决我的问题。我试着在这里找到的所有方式,但仍然没有。请帮忙!

这是我的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"/>

我的清单:

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

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

<permission
    android:name="com.my.package.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.my.package.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" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.my.package.Main"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Holo.Light" >
        <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.gms.version"
        android:value="@integer/google_play_services_version" />

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

我的主要:

package com.my.package;

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

public class Main extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

我的LogCat:

11-08 21:55:45.802: E/AndroidRuntime(8319): FATAL EXCEPTION: main
11-08 21:55:45.802: E/AndroidRuntime(8319): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.package/com.my.package.Main}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread.access$600(ActivityThread.java:135)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.os.Looper.loop(Looper.java:137)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread.main(ActivityThread.java:4849)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at java.lang.reflect.Method.invokeNative(Native Method)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at java.lang.reflect.Method.invoke(Method.java:511)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at dalvik.system.NativeStart.main(Native Method)
11-08 21:55:45.802: E/AndroidRuntime(8319): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:411)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Activity.setContentView(Activity.java:2087)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at com.my.package.Main.onCreate(Main.java:13)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Activity.performCreate(Activity.java:5236)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
11-08 21:55:45.802: E/AndroidRuntime(8319):     ... 11 more
11-08 21:55:45.802: E/AndroidRuntime(8319): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Fragment.instantiate(Fragment.java:584)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Fragment.instantiate(Fragment.java:552)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Activity.onCreateView(Activity.java:4884)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-08 21:55:45.802: E/AndroidRuntime(8319):     ... 20 more
11-08 21:55:45.802: E/AndroidRuntime(8319): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
11-08 21:55:45.802: E/AndroidRuntime(8319):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-08 21:55:45.802: E/AndroidRuntime(8319):     at android.app.Fragment.instantiate(Fragment.java:574)
11-08 21:55:45.802: E/AndroidRuntime(8319):     ... 23 more

2 个答案:

答案 0 :(得分:0)

您需要将Google Play Services库导入您应用中的库项目

查看此链接如何导入库

http://developer.android.com/tools/support-library/setup.html#add-library

答案 1 :(得分:0)

也许您的片段声明不正确? http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html上的示例使用class="com.google.android.gms.maps.MapFragment"代替android:name="com.google.android.gms.maps.MapFragment"