我在使用与其他应用程序中使用的代码相同的代码尝试使用GoogleMapApi V2时遇到了问题。 我想要的只是做StartActivity(MapActivityFragment);没有错误
我有这些权限
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.egdigital.appetablissement.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.egdigital.appetablissemen" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<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" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="theApiKey" />
<activity
android:name="com.egdigital.appetablissement.ActivityGoogleMap"
android:configChanges="orientation"
android:label="@string/app_name" >
</activity>
包含地图支持片段的XML:activity_maps
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
此类用于管理地图
public class ActivityGoogleMap extends SherlockFragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
}
}
我已将ActionBarSherlock和googlePlayServices-lib 列为库
还包括android-support-v4.jar 作为外部jar并将其添加到依赖项中
当我执行StartActivity(MapActivityFragment)时,我遇到了一个很大的错误:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.egdigital.appetablissement/com.egdigital.appetablissement.ActivityGoogleMap}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.egdigital.appetablissement-1.apk
答案 0 :(得分:1)
看起来<application>
中的<meta-data>
和AndroidManifest.xml
元素存在一些错误的格式。
所以,以下内容:
<application
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="theApiKey" />
<activity
android:name="com.egdigital.appetablissement.ActivityGoogleMap"
android:configChanges="orientation"
android:label="@string/app_name" >
</activity>
......应改为:
<application>
<activity
android:name="com.egdigital.appetablissement.ActivityGoogleMap"
android:configChanges="orientation"
android:label="@string/app_name" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="theApiKey">
</application>
Android Maps API v2文档: https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application
...说:
在AndroidManifest.xml中,将[meta-data]元素添加为元素的子元素,方法是在结束标记
</application>
之前插入。