我有问题,因为我正在按照本教程https://www.youtube.com/watch?v=vQ__ECAEAS0,如何在android项目中实现Google maps v2,我在新活动中完全喜欢教程,然后我尝试打开新活动,应用程序是每次都崩溃:抱歉新手知道...
创建新活动:
public void openMap(View view) {
Intent intent = new Intent(this, MapMain.class);
startActivity(intent);
}
XML:
<Button
android:id="@+id/bMapas"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_above="@+id/buttonSettings"
android:layout_toLeftOf="@+id/textpowererdBy"
android:background="@drawable/st_nohow_b"
android:onClick="openMap"
android:text="@string/map" />
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.test.app"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="nl.test.app.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="nl.test.app.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainMenu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapMain"
android:label="@string/title_activity_map_main" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAnNGd2_lI-3-wS0XR06czsjDQNTAATQXF" />
</application>
</manifest>
logcat的
08-12 13:31:25.536: E/AndroidRuntime(440): FATAL EXCEPTION: main
08-12 13:31:25.536: E/AndroidRuntime(440): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.test.app/nl.test.app.MapMain}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread.access$500(ActivityThread.java:122)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.os.Looper.loop(Looper.java:132)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread.main(ActivityThread.java:4123)
08-12 13:31:25.536: E/AndroidRuntime(440): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 13:31:25.536: E/AndroidRuntime(440): at java.lang.reflect.Method.invoke(Method.java:491)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-12 13:31:25.536: E/AndroidRuntime(440): at dalvik.system.NativeStart.main(Native Method)
08-12 13:31:25.536: E/AndroidRuntime(440): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.Activity.setContentView(Activity.java:1786)
08-12 13:31:25.536: E/AndroidRuntime(440): at nl.test.app.MapMain.onCreate(MapMain.java:16)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.Activity.performCreate(Activity.java:4397)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
08-12 13:31:25.536: E/AndroidRuntime(440): ... 11 more
08-12 13:31:25.536: E/AndroidRuntime(440): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5089000 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" />
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.internal.u.I(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.internal.u.H(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.SupportMapFragment$b.jz(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.dynamic.a.a(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
08-12 13:31:25.536: E/AndroidRuntime(440): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:660)
08-12 13:31:25.536: E/AndroidRuntime(440): ... 21 more
答案 0 :(得分:1)
我注意到的一件事是你没有把这部分放在你的清单文件中:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
如果没有此清单文件中的Google Maps API V2
部分, meta-data
将无法运行。
如果在进行此更改后仍无法正常工作,请尝试查看我就此主题撰写的博文:
您也可以查看本教程,确保获得密钥并以正确的方式设置API控制台: