我一整天都看到了这个错误:
06-18 15:40:14.343: E/AndroidRuntime(11830): FATAL EXCEPTION: main
06-18 15:40:14.343: E/AndroidRuntime(11830): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.os.Looper.loop(Looper.java:137)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread.main(ActivityThread.java:4921)
06-18 15:40:14.343: E/AndroidRuntime(11830): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 15:40:14.343: E/AndroidRuntime(11830): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-18 15:40:14.343: E/AndroidRuntime(11830): at dalvik.system.NativeStart.main(Native Method)
06-18 15:40:14.343: E/AndroidRuntime(11830): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.Activity.setContentView(Activity.java:1924)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.example.googlemap.MainActivity.onCreate(MainActivity.java:21)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.Activity.performCreate(Activity.java:5188)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
06-18 15:40:14.343: E/AndroidRuntime(11830): ... 11 more
06-18 15:40:14.343: E/AndroidRuntime(11830): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.internal.u.B(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.internal.u.A(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.MapFragment$b.ip(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.dynamic.a.a(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.app.Activity.onCreateView(Activity.java:4838)
06-18 15:40:14.343: E/AndroidRuntime(11830): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
06-18 15:40:14.343: E/AndroidRuntime(11830): ... 21 more
我在SO上关注了很多问题和答案,但结果是一样的。
我的清单是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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="com.example.googlemap.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="something-something" />
</application>
</manifest>
我的MainActivity.java:
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
我的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
它与我从某些网站获得的完全相同。有人可以帮我从这里出去吗??谢谢!!
答案 0 :(得分:2)
你的locgcat清楚地说了
Caused by: java.lang.IllegalStateException: The meta- data tag in your app's AndroidManifest.xml does not have the right value. Expected 4323000 but found 0. You must have the following declaration within the element:
尝试使用<meta-data>
文件中<application>
标记下的manifest.xml
标记添加Google Play服务版本,例如
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
答案 1 :(得分:0)
我感到困惑的是,需要两个元数据。
One with api key and another with google service.
另一个我感到困惑的地方是,我不知道是什么
android:value="@integer/google_play_services_version"
意思是。
所以你应该简单地复制粘贴线。并且只能稍后试着