谷歌地图 - RuntimeException的 - 错误充气类片段 [英] google map - runtimeexception - error inflating class fragment

查看:184
本文介绍了谷歌地图 - RuntimeException的 - 错误充气类片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试查看显示在地图上,但它不工作。我得到一个RuntimeException的:

I just try to view a map on the display, but it does not work. I get an runtimeexception:

01-17 19:16:47.066: E/AndroidRuntime(6605): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

Java的:

Java:

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;




public class MainActivity extends FragmentActivity {
 getSupportFragmentManager().findFragmentById(R.id.map))

@Override
protected void onCreate(Bundle savedInstanceState) {
    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    SupportMapFragment fragment = new SupportMapFragment();
    getSupportFragmentManager().beginTransaction()
            .add(android.R.id.content, fragment).commit();

    setContentView(R.layout.activity_main);

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    GoogleMap map = ((SupportMapFragment) 
 getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}


}

清单

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

<uses-sdk
    android:minSdkVersion="8"
            android:targetSdkVersion="16"/>
  <permission
      android:name="com.example.maptest.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <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="com.example.mapdemo.permission.MAPS_RECEIVE"/>


    <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" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="removed"/>


    <activity
        android:name="com.example.maptest.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <category android:name="android.intent.category.EMBED"/>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
           <uses-library android:name="com.google.android.maps"/>
</application>

</manifest>

布局的xml:

layout xml:

<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"
    tools:context=".MainActivity" >

  <fragment xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/map"
     android:name="com.google.android.gms.maps.SupportMapFragment"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     class="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>

关键是V2,我跟着严谷歌的教程中,我发现了。我还进口了Android的播放服务。

The key is v2 and i followed strict the google tutorial i found. I also imported android play services.

有人能帮助我吗? :)

Could someone help me please? :)

推荐答案

我想的地图API第2版时,也有类似的错误。但是,我不知道是否会帮助你。

I had a similar error when trying the Map API v2. However, I don't know whether it will help you.

我的问题是,谷歌播放-services_lib必须包括一个图书馆。在Eclipse中,你可以做到这一点,如下所示:

My problem was that the google-play-services_lib had to be included as a library. In Eclipse, you can do this as follows:

  1. 使用了Android SDK管理器来下载库。
  2. 创建一个新的Android项目从现有的code,你指向谷歌播放services_lib用于安装SDK中的文件夹中。
  3. 在项目 - >属性 - > Android的标志,这个项目为是库
  4. 在您的项目中,也开项目 - >属性 - > Android的,然后单击库中的部分添加。选择谷歌播放-services_lib。

至少这为我工作。

这篇关于谷歌地图 - RuntimeException的 - 错误充气类片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆