java - Android - 膨胀类 fragment 时出错(试图让谷歌地图 api v2 工作)

标签 java android xml google-maps

我到处搜索此错误的解决方案,但似乎找不到适合我的解决方案。每次我运行程序都会崩溃,问题似乎出在 XML 文件中的 fragment 标记中。

如果您能看一下代码,非常感谢。

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
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>

主要 Activity :

package jondadi.atm;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
  }

} 

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jondadi.atm"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="18" />

<permission
   android:name="jondadi.atm.maps.permission.MAPS_RECEIVE"
   android:protectionLevel="signature" />

<uses-feature
   android:glEsVersion="0x00020000"
   android:required="true" />

<uses-permission android:name="jondadi.atm.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" />



<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="jondadi.atm.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.maps.v2.API_KEY"
        android:value="AIzaSyD0L90SyrdZRdn3v4aQe05HUQJi1viLiyA" />

</application>

</manifest>

Logcat 错误(日志要长得多,如果您想要全部,请告诉我):

11-06 02:29:02.165: E/AndroidRuntime(8238): FATAL EXCEPTION: main
11-06 02:29:02.165: E/AndroidRuntime(8238): java.lang.RuntimeException: Unable to start activity ComponentInfo{jondadi.atm/jondadi.atm.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
11-06 02:29:02.165: E/AndroidRuntime(8238):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)

11-06 02:29:02.165: E/AndroidRuntime(8238): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 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" />
11-06 02:29:02.165: E/AndroidRuntime(8238): Caused by: java.lang.IllegalStateException: 

最佳答案

您缺少:

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

在应用程序元素内。这将解决:

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 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" />

关于java - Android - 膨胀类 fragment 时出错(试图让谷歌地图 api v2 工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19803011/

相关文章:

java - 使用 JButtons 清除 JTextFields

java - ClassNotFoundException 错误。 Eclipse IDE 出现问题

php - 在 PHP 中使用 saveXML 保存 CDATA

java - 考虑定义 EntityManagerFactory 类型的 bean Spring boot

java - Android Studio - 未安装 HAX 内核模块

android - 如何在 TabLayout 中为每个 Activity 设置图标到标题栏

android - 用于 Android 和 C 代码开发的 IntelliJ

xml - 在模块路径或类路径上未找到 JAXB-API 的 javax.xml.bind.JAXBException 实现

c# - 从 Xslt 中的嵌入代码获取 Xml

java - Servlet session cookie 篡改和安全