2

我有一個活動,我想要做的是開始一個新的活動,其中包含一個谷歌地圖片段API v2遵循這個例子(https://developers.google。 COM /地圖/文檔/安卓/啓動)。我得到一個運行時錯誤運行時錯誤「膨脹類碎片」

"Binary XML file line #4: Error inflating class fragment" 

該活動的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" >  
    <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"/> 
</LinearLayout> 

,這是該活動的類:

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

public class MapsActivity extends Activity { 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.map_act); 

    // TODO Auto-generated method stub 
} 

} 

,這是logcat的:

12-18 11:59:37.584: W/dalvikvm(9480): threadid=1: thread exiting with uncaught exception (group=0x2b6a3300) 
12-18 11:59:37.594: E/AndroidRuntime(9480): FATAL EXCEPTION: main 
12-18 11:59:37.594: E/AndroidRuntime(9480): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dimacroitori.supermarket/com.dimacroitori.supermarket.MapsActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread.access$600(ActivityThread.java:144) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.os.Looper.loop(Looper.java:137) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread.main(ActivityThread.java:4939) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at java.lang.reflect.Method.invoke(Method.java:511) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at dalvik.system.NativeStart.main(Native Method) 
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class fragment 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:257) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Activity.setContentView(Activity.java:1867) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at com.exmaple.MapsActivity.onCreate(MapsActivity.java:12) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Activity.performCreate(Activity.java:5008) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  ... 11 more 
12-18 11:59:37.594: E/AndroidRuntime(9480): 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 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Fragment.instantiate(Fragment.java:584) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Fragment.instantiate(Fragment.java:552) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Activity.onCreateView(Activity.java:4656) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  ... 20 more 
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  at android.app.Fragment.instantiate(Fragment.java:574) 
12-18 11:59:37.594: E/AndroidRuntime(9480):  ... 23 more 

有人可以解釋我什麼,我做錯了什麼?

+0

'ClassNotFoundException'可能意味着您沒有將包含該片段的[library](http://developer.android.com/google/play-services/setup.html)添加到您的應用 – zapl

+0

@zapl,對不起對於我的noob問題,但我該怎麼辦? – slyder07

回答