我有一项活动,我尝试做的是按照此示例启动一个包含Google Maps Fragment API v2的新活动(https://developers.google.com/maps/documentation/android /开始)。我收到运行时错误
"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>
这是活动的课程:
import 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 :(得分:0)
确保您的应用程序added the Google Play Services Android library project已定义该类。还要确保您在API级别11或更高版本的环境中运行应用程序,因为您尝试使用本机片段(而不是Android支持包的后端)。