首先,过去我能够运行谷歌地图v2
现在我遇到了这个例外:
06-12 21:31:14.289: E/AndroidRuntime(17491): FATAL EXCEPTION: main
06-12 21:31:14.289: E/AndroidRuntime(17491): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamroma.example/com.williamroma.example.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.os.Looper.loop(Looper.java:130)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread.main(ActivityThread.java:3701)
06-12 21:31:14.289: E/AndroidRuntime(17491): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 21:31:14.289: E/AndroidRuntime(17491): at java.lang.reflect.Method.invoke(Method.java:507)
06-12 21:31:14.289: E/AndroidRuntime(17491): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
06-12 21:31:14.289: E/AndroidRuntime(17491): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
06-12 21:31:14.289: E/AndroidRuntime(17491): at dalvik.system.NativeStart.main(Native Method)
06-12 21:31:14.289: E/AndroidRuntime(17491): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-12 21:31:14.289: E/AndroidRuntime(17491): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.Activity.setContentView(Activity.java:1657)
06-12 21:31:14.289: E/AndroidRuntime(17491): at com.williamroma.example.MainActivity.onCreate(MainActivity.java:11)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
06-12 21:31:14.289: E/AndroidRuntime(17491): ... 11 more
06-12 21:31:14.289: E/AndroidRuntime(17491): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.williamroma.example-1.apk]
06-12 21:31:14.289: E/AndroidRuntime(17491): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-12 21:31:14.289: E/AndroidRuntime(17491): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-12 21:31:14.289: E/AndroidRuntime(17491): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
06-12 21:31:14.289: E/AndroidRuntime(17491): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-12 21:31:14.289: E/AndroidRuntime(17491): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-12 21:31:14.289: E/AndroidRuntime(17491): ... 19 more
主要节日是
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.williamroma.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.williamroma.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.williamroma.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXXXXXXXXX" />
</application>
</manifest>
我的活动是:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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"/>
我将android目标设置为2.2 google api,我在手机上测试它2.3
请帮助
答案 0 :(得分:3)
你的min sdk是8.你应该使用支持片段。
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
您的活动必须延长FragmentActivity
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap();
确保您已添加支持库
同时确保导入以下内容
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;