3

編輯:對於那些努力與此,結帳this link。仔細跟蹤它,但它確實有效!關鍵部分是使用keytool來針對您的調試密鑰庫生成SHA1哈希。另外,不要忘記添加一個發佈!谷歌地圖Android API v2 ClassNotFound運行時錯誤

我一直在試圖安裝谷歌地圖API的Android v2和設置的一切行動作爲後說:我得到這個運行時異常ClassNotFound

01-02 16:29:07.927: E/AndroidRuntime(12508): FATAL EXCEPTION: main 
01-02 16:29:07.927: E/AndroidRuntime(12508): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Looper.loop(Looper.java:130) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.main(ActivityThread.java:3701) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invokeNative(Native Method) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invoke(Method.java:507) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.NativeStart.main(Native Method) 
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Activity.setContentView(Activity.java:1657) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.example.app.MapActivity.onCreate(MapActivity.java:11) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 11 more 
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.app-1.apk] 
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createView(LayoutInflater.java:471) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 20 more 

有沒有人遇到過嗎?

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" 
    class="com.google.android.gms.maps.MapFragment"/> 

MapActivity:

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

public class MapActivity extends Activity { 

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

回答

4

你的活動需要從支持庫

+0

Sorted! :D謝謝 –

2

延長FragmentActivity試試這個代碼工作完美幫助全給你。

XML

<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.SupportMapFragment"/> 

</RelativeLayout> 

的Java

package com.example.androidmapsv2; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 

import android.app.AlertDialog; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.Toast; 

public class MainActivity extends FragmentActivity { 
final int RQS_GooglePlayServices = 1; 
private GoogleMap myMap; 

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

    FragmentManager myFragmentManager = getSupportFragmentManager(); 
    SupportMapFragment mySupportMapFragment 
    = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map); 
    myMap = mySupportMapFragment.getMap(); 
} 
@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); 

    if (resultCode == ConnectionResult.SUCCESS){ 
    Toast.makeText(getApplicationContext(), 
    "isGooglePlayServicesAvailable SUCCESS", 
    Toast.LENGTH_LONG).show(); 
    }else{ 
    GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices); 
    } 
} 
} 
+0

我最終得到了它,但它比這種方法簡單得多!使用該代碼我無法讓它顯示映射圖像,但加載了控件。 –

+0

實際上,你給KeTaN的鏈接是指API v1,但是關於API v2的問題 – zest

1

你的AVD運行?如果是的話試試真實的設備

+0

上面的答案解決了這個問題,是的,我確實閱讀過文檔:AVD;) –