我正在开发一个简单的地图。我是新手。我使用了提供的教程开发了
maps developing
我的logcat错误看起来像这样
01-20 15:13:23.511: W/dalvikvm(28896): threadid=1: thread exiting with uncaught exception (group=0x417379a8)
01-20 15:13:23.520: E/AndroidRuntime(28896): FATAL EXCEPTION: main
01-20 15:13:23.520: E/AndroidRuntime(28896): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nuappz.gotcha/com.nuappz.gotcha.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
01-20 15:13:23.520: E/AndroidRuntime(28896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
01-20 15:13:23.520: E/AndroidRuntime(28896): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
01-20 15:13:23.520: E/AndroidRuntime(28896): at android.app.ActivityThread.access$600(ActivityThread.java:156)
01-20 15:13:23.520: E/AndroidRuntime(28896): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
01-20 15:13:23.520: E/AndroidRuntime(28896): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.MapFragment$b.eb(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.dynamic.a.a(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896): at android.app.Activity.onCreateView(Activity.java:4734)
我的代码是
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
}
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nuappz.gotcha"
android:versionCode="1"
android:versionName="1.0" >`
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<permission
android:name="com.nuappz.gotcha.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.nuappz.gotcha.android.locationapi.maps.permission.MAPS_RECEIVE" />
<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" />
<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.nuappz.gotcha.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>
</application>
</manifest>
这里有什么问题。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
答案 0 :(得分:0)
MainActivity.xml中应该有XML。该例外已经说明它无法使用布局:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
答案 1 :(得分:0)
此处MainActivity
必须延伸FragmentActivity
所以改变
public class MainActivity extends FragmentActivity{
}
答案 2 :(得分:0)
当你阅读它时,例外是不言自明的:
A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
因此,请将以下内容添加到您的清单application
元素中:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
答案 3 :(得分:0)
实际上问题出在MainActivity.java文件中 MainActivity必须扩展到FragmentActivity而不是Activity 因为我正在通过片段显示地图。
答案 4 :(得分:0)
这是我几天前遇到的特殊问题。问题是你使用的是 SHA1 KEY ,这不是用于调试的,所以我建议你不要在导出时获取密钥