二进制 XML 文件第 8 行:膨胀类片段时出错,Google 地图

2023-11-22

在此应用程序中,我尝试添加功能性 V2 谷歌地图。我已经查看了大多数关于创建活动、获取地图密钥以及创建 xml 文件的教程,以尝试看看我是否错过了任何步骤(我已经完成了 4 次),但事实并非如此好像我错过了任何一步。

Here是我使用的网站:

当我在手机上运行我的应用程序时(因为 Google Play 服务无法在模拟器上运行),它给了我以下两个错误:

  02-11 22:10:54.690: E/AndroidRuntime(4526): java.lang.RuntimeException: Unable to       start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.ShowActivity}:       android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  02-11 22:10:54.690: E/AndroidRuntime(4526): 

  Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment       com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public

这是我的活动:

package com.example.myfirstapp;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.maps.*;
import com.google.android.gms.maps.MapFragment;
public class ShowActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_map, menu);
    return true;
}

//@Override
//protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    //return false;
//}

    }

抱歉格式不正确,但这是我的 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=".ShowActivity" >

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

  </RelativeLayout>

我已经导入了 Google API 和 google play 服务,因此所有导入都正常,这让我想知道为什么第二个错误说 MapFragment 为空。 清单文件代码:

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

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_READ" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.example.myfirstapp.permission.MAPS_RECEIVE" />
<permission
    android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myfirstapp.MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <meta-data
            android:name="android.app.default_searchable"
            android:value=".SearchResultsActivity" />
    </activity>
    <activity
        android:name="com.example.myfirstapp.SearchResultsActivity"
        android:label="@string/title_activity_search_results"
        android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>

        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>
    <activity
        android:name="com.example.myfirstapp.AddContacts"
        android:label="@string/title_activity_add_contacts" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.ContactActivity"
        android:label="@string/title_activity_contact" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.DisplayInfo"
        android:label="@string/title_activity_display_info" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:name="com.example.myfirstapp.SomeProvider"
        android:authorities="com.example.myfirstapp.SomeProvider" >
    </provider>

    <activity
        android:name="com.example.myfirstapp.EditContacts"
        android:label="@string/title_activity_edit_contacts" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.DeleteContact"
        android:label="@string/title_activity_delete_contact" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.FlightInfo"
        android:label="@string/title_activity_flight_info" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.EventInfo"
        android:label="@string/title_activity_event_info" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.ContactsActivity"
        android:label="@string/title_activity_contacts" >
    </activity>
    <activity
        android:name="com.example.myfirstapp.ShowActivity"
        android:label="@string/title_activity_map" >
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="removed" />
<uses-library android:name="com.google.android.maps" />
</application>

</manifest>

尝试下面的代码:

public class ShowActivity extends android.support.v4.app.FragmentActivity {
    private GoogleMap mMap;

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

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }
}

XML文件代码:

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

清单文件代码:

    <permission
        android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
      <uses-permission android:name="com.example.myfirstapp.permission.MAPS_RECEIVE"/>
        <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
      <uses-sdk
                android:minSdkVersion="8"
                android:targetSdkVersion="16"/>
        <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission         android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
      <application
        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" />
   </application>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

二进制 XML 文件第 8 行:膨胀类片段时出错,Google 地图 的相关文章

  • gradle更新后无法找到方法(无法编译项目)

    我尝试将项目中的 gradle 版本更新为 4 1 milestone 1 以下这些说明 https developer android com studio build gradle plugin 3 0 0 migration html
  • android edittext中的字符映射

    我想让我的编辑文本就像我写字符 g 时一样 它是相关的映射自定义字符应该写成印地语中的 我认为应该有字符映射 但没有知识任何人都可以帮助我 怎么做 其他应用程序https play google com store apps details
  • fetchUuidsWithSdp 的奇怪 UUID 逆转

    我有一个在树莓派上运行的 python 蓝牙服务器 使用 PyBluez 我在服务器中使用的uuid是 8f86d132 4ab8 4c15 b8df 0b70cf10ea56 我正在打电话device fetchUuidsWithSdp
  • Recyclerview 动态部分不使用任何第三个库

    我想将标头添加到 recyclerview 我正在尝试使用来实现它 Override public int getItemViewType int position depends on your problem if position 0
  • Android应用程序组件销毁和重新创建的详细信息

    有人可以向我提供一些具体的 值得信赖的 最好是简洁的 信息 内容如下 系统销毁和 如果适用 重新创建组件的顺序 片段 活动 活动的线程 异步任务 计时器 静态数据 类何时卸载 其他类中的线程 异步任务 定时器 主机 TabActivity
  • 自定义首选项中的android首选项水平分隔线?

    我创建了自己的自定义首选项对象来扩展首选项 我创建它们只是因为这些自定义数据类型没有首选项 一切正常 但我的自定义首选项没有相同的外观 因为它们缺少系统首选项对象具有的水平分隔线 我已经查找了创建水平分隔线的代码 但我找不到它是在哪里完成的
  • 在 Cordova 应用程序中获取额外功能

    我们有两个 Android 应用程序 一个使用本机 Java 实现 另一个使用 Ionic 编写 Ionic 应用程序启动我的应用程序 这是使用灯插件 https github com lampaa com lampa startapp 我
  • ExoPlayer2 - 如何使 HTTP 301 重定向工作?

    我开始使用 ExoPlayer 来传输一些音频 一切都很顺利 直到我遇到一个带有 301 永久移动 重定向的 URL ExoPlayer2 默认情况下不处理该问题 我已经看过这个线程 https github com google ExoP
  • 在 android 中建立与 MySQL 的池连接

    我需要从我的 Android 应用程序访问 MySQL 数据库 现在所有的工作都通过 DriverManager getConnection url 等等 但我必须从多个线程访问数据库 所以我必须使用连接池 问题1 是 com mysql
  • 为什么是 javascript:history.go(-1);无法在移动设备上工作?

    首先 一些背景 我有一个向用户呈现搜索页面 html 表单 的应用程序 填写标准并单击 搜索 按钮后 结果将显示在标准部分下方 在结果列表中 您可以通过单击将您带到新页面的链接来查看单个结果的详细信息 在详细信息页面中 我添加了一个 返回结
  • 从 BroadcastReceiver 类调用活动方法

    我知道我可以做一个内部接收器类来调用接收器中的任何方法 但我的主要活动太大了 要做的事情也很多 因此 我需要一个扩展广播接收器的类 但它不是内部类 并且可以从我的主要活动中调用一种方法 我不知道是否可能 但我的活动是家庭活动和 single
  • Android - AudioRecord类不读取数据,audioData和fftArray返回零

    我是 Android 新手 一直在开发音调分析器应用程序 最低 SDK 8 我读了很多关于如何实现 Audiorecord 类的文章 但我想知道为什么它在我录制时不读取任何数据 我尝试显示 audioData 和 fftArray 的值 但
  • okhttp 获取失败响应

    我已经在我的 android 客户端中实现了 okhttp 来进行网络调用 当我收到失败响应时 我会收到失败代码以及与该代码相关的文本作为消息 但我没有收到服务器发送给我的自定义失败响应 在我实施的代码中的失败响应中 我收到的消息只是 错误
  • Android 2.3 模拟器在更新位置时崩溃

    我正在使用 Eclipse 编写和调试 Android 应用程序 我需要做的事情之一是更新设备的位置 因此我尝试使用模拟器控制窗口中的位置控制面板 在 手动 选项卡上 我选择 十进制 输入有效的纬度和经度 然后单击 发送 不幸的是 接下来发
  • 我应该释放或重置 MediaPlayer 吗?

    我有自己的自定义适配器类 称为 WordAdapter 并且我正在使用媒体播放器 名为pronounce WordAdapter 类中的全局变量 我有不同的活动 其中每个列表项都有线性布局 名为linearLayout 我正在设置onCli
  • 如何在 Android 中从 WorkManager 取消工作?

    我已经保存了 WorkManagerUUID转换成String在领域数据库中 这是代码 Constraints constraints new Constraints Builder setRequiredNetworkType Netwo
  • Dagger 2 没有生成我的组件类

    我正在使用 Dagger 2 创建我的依赖注入 几个小时前它还在工作 但现在不再生成组件 这是我创建组件的地方 public class App extends Application CacheComponent mCacheCompon
  • 卡片视图 单击卡片移至新活动

    我是 Android 编程新手 正在研究卡片布局 我想知道如何使其可点击 android clickable true android foreground android attr selectableItemBackground 我的卡
  • 没有用于警告的设置器/字段 Firebase 数据库检索数据填充列表视图

    我只是想将 Firebase 数据库中的数据填充到我的列表视图中 日志显示正在检索数据 但适配器不会将值设置为列表中单个列表项中的文本 它只说 没有二传手 场地插入值 这让我觉得我的设置器没有正确制作 但 Android Studio 自动
  • 通过系统应用程序以编程方式静默安装 apk(无需 root)

    我有带有 android sharedUserId android uid system UID 1000 的系统级应用程序 设备未root INSTALL PACKAGES 权限包含在清单中 我可以静默安装下载的 apk 吗 我已经发现这

随机推荐

  • LoadLibrary project.dll 失败。指定的模块无法找到

    当我尝试注册我的 C ATL 项目的 32 位版本时 regsvr32 project dll 我收到此错误 LoadLibrary project dll failed The specified module could not be
  • 将通用 Class 参数限制为实现 Map 的类

    我正在尝试写一个Map建设者 构造函数之一将允许客户端指定类型Map他们希望建立 public class MapBuilder
  • 删除/替换列值中的特殊字符?

    我有一个表列 其中包含我想从中删除所有连字符的值 这些值可能包含多个连字符并且长度各不相同 示例 对于我想要替换的所有值123 ABCD efghi with 123ABCDefghi 删除所有连字符并更新表中所有列值的最简单方法是什么 您
  • Windows Python2.7 mysqldb安装错误

    我正在尝试为 Python 安装 mysqldb 我正在运行 pip install mysql python 我不断收到此错误 运行 build ext构建 mysql 扩展创建 build temp win32 2 7创建 build
  • 在 MVC 框架中的 Javascript 文件中使用内联 C#

    我正在尝试使用 MVC 框架让内联 C 在我的 JavaScript 文件中工作 我编写了这个小测试代码 document ready function alert 当此代码在视图内部使用时 它可以完美地工作 当我离开我的 aspx 视图并
  • AngularJS:将服务注入 HTTP 拦截器(循环依赖)

    我正在尝试为我的 AngularJS 应用程序编写一个 HTTP 拦截器来处理身份验证 这段代码可以工作 但我担心手动注入服务 因为我认为 Angular 应该自动处理这个问题 app config httpProvider functio
  • 如何在matlab中制作圆并在其中生成随机点

    hello i want to ask a question how to make a circle in matlab and mark its center and generate a certain number of rando
  • 何时使用无符号值而不是有符号值?

    什么时候适合使用无符号变量而不是有符号变量 那么在一个for loop 我听到了很多关于这个问题的意见 我想看看是否有任何类似的共识 for unsigned int i 0 i lt someThing length i SomeThin
  • Haskell 中的 IO Int 和类似单元测试

    From 九十九道 Haskell 问题 问题23 从列表中提取给定数量的随机选择的元素 这是部分解决方案 为简单起见 此代码仅从列表中选择一个元素 import System Random randomRIO randItem a gt
  • 如果mysql表不存在则创建

    我不太使用 php mysql 但我需要一个我认为相对简单的任务 检查表是否存在 如果不存在则创建它 我什至无法获得有用的错误消息 并且数据库中没有创建表 显然我的语法有问题
  • 禁用 jqGrid 选定行的子网格扩展

    问题 带有子网格的 jqGrid 我想禁用主网格某些行的展开 折叠功能 我其实找到了一个方法 grid jqGrid setGridParam afterInsertRow function rowid aData rowelem var
  • 如何在对象数组中查询算法数据

    我有一个数据数组 其中 Algolia 索引中包含多个对象 如下所示 status available startDate 2000 10 20 endDate 2022 10 20 availablePlatform 1 2 3 avai
  • 将表标准化为第三范式

    这道题显然是一道家庭作业题 我听不懂我的教授 也不知道他在选举期间说了什么 我需要一步一步地进行说明 首先将下表规范化为 1NF 然后是 2NF 然后是 3NF 我感谢任何帮助和指导 好吧 我希望我都记得正确 让我们开始吧 Rules 让它
  • 如何使用节点谷歌客户端 API 来获取已获取令牌的用户配置文件?

    通过获取用户个人资料信息curl curl i https www googleapis com userinfo v2 me H Authorization Bearer a google account access token 通过获
  • 更改默认 JLabel 字体

    我将如何为所有人设置默认字体JLabel实例 而不是为每个设置字体JLabel独立 Use UIManager定义 JLabel 的默认字体 import java awt FlowLayout import java awt Font i
  • 收益返回和异常处理[重复]

    这个问题在这里已经有答案了 我刚刚遇到一个使用yield return 的方法 但没有抛出我期望的ArgumentException 的情况 我在这里用最简单的类重建了这个案例 class Program static void Main
  • 将十六进制字符(连字)转换为 utf-8 字符

    我有一个从 pdf 文件转换而来的文本内容 文本中有一些不需要的字符 我想将它们转换为 utf 8 字符 例如 人工免疫系统 转换为 Arti 社会免疫系统 像一个字符一样转换 我用了gdex学习ascii角色的价值 但我不知道如何将其替换
  • 如何将WebView设置为非全屏?

    我正在尝试在我的 Android 应用程序中使用 WebView 我正在代码端 而不是 XML 创建我的 webview 我的问题是 当我调用 webview 的 loadUrl 方法时 webview 进入全屏模式 如何保持 webvie
  • 尝试编译此代码是否会导致 IDE 终止或编译器无法运行?

    提防Exit内联函数中的命令用法 我这里一直使用Delphi XE3 Symptom 在某些情况下 当调用包含以下内容的内联函数时Exit命令 以及返回值使用内联函数的directly in WriteLn 编译器报告错误消息 dcc 退出
  • 二进制 XML 文件第 8 行:膨胀类片段时出错,Google 地图

    在此应用程序中 我尝试添加功能性 V2 谷歌地图 我已经查看了大多数关于创建活动 获取地图密钥以及创建 xml 文件的教程 以尝试看看我是否错过了任何步骤 我已经完成了 4 次 但事实并非如此好像我错过了任何一步 Here是我使用的网站 当