2014-09-02 53 views
0

我已經廣泛搜索了一個答案,但似乎現在幾乎不可能修復,儘管我一直在試圖解決這個問題整天。ClassNotFoundException MapFragment使用地圖v2和播放服務修訂版19

相應的谷歌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修訂版。

主要活動看起來與從谷歌發佈的樣本完全相同。 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> 

當按鍵被實際插入。

非常感謝,希望我能解決這個問題。

+0

嘗試從FragmentActivity擴展而不是Activity ... – Jorgesys 2014-09-02 15:40:00

回答

0

我通過將我的項目遷移到Android Studio來解決了這個問題。看來這個庫在eclipse中沒有正確鏈接,我很快就試圖調試ide問題。

相關問題