ClassNotFoundException MapFragment使用Maps v2& Play Services Rev 19

时间:2014-09-02 15:29:56

标签: java android maps

我已经广泛搜索了一个答案但是现在几乎不可能修复,尽管我一直试图解决这个问题。

将相应的Google Play服务库链接到简单的地图应用程序后,我不断获得以下日志输出

09-02 22:00:01.140: E/AndroidRuntime(21487): FATAL EXCEPTION: main
09-02 22:00:01.140: E/AndroidRuntime(21487): Process: com.example.mapdemo, PID: 21487
09-02 22:00:01.140: E/AndroidRuntime(21487): 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
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread.access$900(ActivityThread.java:173)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.os.Looper.loop(Looper.java:136)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread.main(ActivityThread.java:5579)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at java.lang.reflect.Method.invokeNative(Native Method)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at java.lang.reflect.Method.invoke(Method.java:515)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at dalvik.system.NativeStart.main(Native Method)
09-02 22:00:01.140: E/AndroidRuntime(21487): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Activity.setContentView(Activity.java:2031)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:11)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Activity.performCreate(Activity.java:5451)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
09-02 22:00:01.140: E/AndroidRuntime(21487):    ... 11 more
09-02 22:00:01.140: E/AndroidRuntime(21487): 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
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Fragment.instantiate(Fragment.java:597)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Fragment.instantiate(Fragment.java:561)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Activity.onCreateView(Activity.java:4989)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
09-02 22:00:01.140: E/AndroidRuntime(21487):    ... 20 more
09-02 22:00:01.140: E/AndroidRuntime(21487): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.example.mapdemo-9.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.mapdemo-9, /vendor/lib, /system/lib]]
09-02 22:00:01.140: E/AndroidRuntime(21487):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-02 22:00:01.140: E/AndroidRuntime(21487):    at android.app.Fragment.instantiate(Fragment.java:583)
09-02 22:00:01.140: E/AndroidRuntime(21487):    ... 23 more

我正在运行游戏服务的第19版。

主要活动看起来与Google发布的示例相同。 https://developers.google.com/maps/documentation/android/start

该代码仅供参考,如下所示。

主要活动

package com.example.mapdemo;

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);
    }
}

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: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.example.mapdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <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=".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>

        <!-- Goolge Maps API Key -->
     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Key Is Here" />
     </application>

</manifest>

实际插入密钥的位置。

非常感谢,希望我能解决这个问题。

1 个答案:

答案 0 :(得分:0)

我通过将项目迁移到Android Studio来解决了这个问题。看来图书馆在eclipse中没有正确链接,我很快就试图调试ide问题。