您好我的Google地图v2有问题我正在关注此链接https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api 但我得到像这样的错误信息
05-22 22:24:07.476: E/AndroidRuntime(19690): FATAL EXCEPTION: main
05-22 22:24:07.476: E/AndroidRuntime(19690): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.easytaxi/com.example.easytaxi.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.os.Looper.loop(Looper.java:130)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-22 22:24:07.476: E/AndroidRuntime(19690): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 22:24:07.476: E/AndroidRuntime(19690): at java.lang.reflect.Method.invoke(Method.java:507)
05-22 22:24:07.476: E/AndroidRuntime(19690): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-22 22:24:07.476: E/AndroidRuntime(19690): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-22 22:24:07.476: E/AndroidRuntime(19690): at dalvik.system.NativeStart.main(Native Method)
05-22 22:24:07.476: E/AndroidRuntime(19690): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-22 22:24:07.476: E/AndroidRuntime(19690): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.Activity.setContentView(Activity.java:1657)
05-22 22:24:07.476: E/AndroidRuntime(19690): at com.example.easytaxi.MainActivity.onCreate(MainActivity.java:12)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-22 22:24:07.476: E/AndroidRuntime(19690): ... 11 more
05-22 22:24:07.476: E/AndroidRuntime(19690): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.easytaxi-1.apk]
05-22 22:24:07.476: E/AndroidRuntime(19690): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-22 22:24:07.476: E/AndroidRuntime(19690): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-22 22:24:07.476: E/AndroidRuntime(19690): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
05-22 22:24:07.476: E/AndroidRuntime(19690): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
05-22 22:24:07.476: E/AndroidRuntime(19690): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
05-22 22:24:07.476: E/AndroidRuntime(19690): ... 19 more`enter code here`
这是我的MainActivity.java文件
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.easytaxi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<permission
android:name="com.example.easytaxi.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.easytaxi.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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="com.example.easytaxi.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="My API Key" />
</application>
</manifest>
这是我的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"/>
我也在我的手机上运行它,而不是在模拟器上,我已经安装了谷歌播放服务,所以我不知道我在哪里犯了错误。提前谢谢。
答案 0 :(得分:1)
t看起来你错过了从\extras\google\google_play_services\libproject\google-play-services_lib.
将其添加为library
到您当前的项目。
确保您已将SupportMapFragment
用于11以下的API。
?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />