我做所有事情,研究每一个但仍然没有工作。 我从这里读了很多页但没有:(
错误日志:
11-18 10:25:46.743: D/AndroidRuntime(24336): Shutting down VM
11-18 10:25:46.743: W/dalvikvm(24336): threadid=1: thread exiting with uncaught exception (group=0x4001d578)
11-18 10:25:46.873: E/AndroidRuntime(24336): FATAL EXCEPTION: main
11-18 10:25:46.873: E/AndroidRuntime(24336): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmap/com.example.gmap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-18 10:25:46.873: E/AndroidRuntime(24336): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.os.Looper.loop(Looper.java:138)
11-18 10:25:46.873: E/AndroidRuntime(24336): at android.app.ActivityThread.main(ActivityThread.java:3701)
11-18 10:25:46.873: E/AndroidRuntime(24336): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 10:25:46.873: E/AndroidRuntime(24336): at java.lang.reflect.Method.invoke(Method.java:507)
主要活动:
package com.example.gmap;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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.gmap"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.gmap.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="AIzaSyDq-Xosuk1Wzyw9WJ4bGjjE6XIhD90QNuA"/>
</application>
</manifest>
和主要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.SupportMapFragment"/>
请任何身体帮助我。
答案 0 :(得分:12)
更改此
public class MainActivity extends Activity {
到
public class MainActivity extends FragmentActivity {
您需要以下
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
在application
标记其标记
答案 1 :(得分:1)
当AndroidManifest.xml文件中缺少某个权限时,我收到此错误。 添加以下权限解决了问题:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
答案 2 :(得分:0)
从手机中删除演示地图应用程序。然后将工作正常。这对我有用。
答案 3 :(得分:-1)