Getting Error while starting Google Map v2
本问题已经有最佳答案,请猛点这里访问。
我整天都在看到此错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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 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上关注了很多问题和答案,但结果是相同的。
我的清单是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <?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> <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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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); } } |
我的布局文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <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> |
与我从某些网站获得的完全相同。有人可以帮我从这里出去吗??谢谢!!
您的locgcat明确表示
1 | 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: |
尝试使用
1 2 3 | <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> |
让我感到困惑的是,需要两个元数据。
1 | One with api key and another with google service. |
另一个让我感到困惑的地方是,我不知道什么
因此,您应该简单地复制粘贴行。而且只能稍后再尝试