我在这里得到2个错误,首先是“无法启动活动”,第二个是“找不到API密钥”。我搜索了很多解决方案,但没有解决问题.API密钥是正确的但仍然是我不知道为什么会出现错误。任何人都可以告诉我代码中有什么问题吗?
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vallabh.googlemapspractice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<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" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.vallabh.googlemapspractice.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.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"
android:value="AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"/>
</application>
</manifest>
activity.xml
<LinearLayout 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"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
答案 0 :(得分:3)
替换此
<meta-data
android:name="com.google.android.maps.v2.AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"
android:value="AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"/>
与
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY" />
答案 1 :(得分:1)
更改
<meta-data
android:name="com.google.android.maps.v2.AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"
android:value="AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"/>
应该是
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBQeTS1IcCPtJxCGvFC4o-Ud5fJHdUmRCY"/>
确保MainActivity
扩展FragmentActivity