谷歌地图 android api v2 应用程序崩溃

2023-12-05

我正在使用 Eclipse helios 和 Android 4.1.2 我已遵循以下文档https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw并完全按照教程中所述进行编码。当我在模拟器上运行我的应用程序时,它显示“除非您更新谷歌播放服务,否则该应用程序不会运行”,但在真实设备上,即索尼xperia,它具有谷歌播放服务更新版本,它崩溃了“应用程序已停止工作”。感谢任何帮助。

这是我的清单

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


    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="16" />

      <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />

    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
     <permission
         android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"
         android:protectionLevel="signature"/>
<uses-permission  android:name="com.example.emeterfinalapp.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"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

         <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name="com.example.emeterfinalapp.EmeterMainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.emeterfinalapp.EnterLocationActivity"
            android:label="@string/title_activity_enter_location"
            android:parentActivityName="com.example.emeterfinalapp.EmeterMainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.emeterfinalapp.EmeterMainActivity" />
        </activity>

        <activity
            android:name="com.example.emeterfinalapp.SelectLocation"
            android:label="@string/title_activity_select_location"
            android:parentActivityName="com.example.emeterfinalapp.EnterMainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.emeterfinalapp.EnterMainActivity" />


         </activity>
        </application>
 <meta-data
   android:name="com.google.android.maps.v2.API_KEY"
   android:value="my api key"/>
    </manifest>

这是我的 main.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=".SelectLocation" >

    <Button
        android:id="@+id/satellite_button"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/mapview_button"
        android:text="@string/satellitebuttontext" />


        <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"
         android:layout_below="@+id/satellite_button"/>


        <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        />

        <Button
            android:id="@+id/mapview_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/mapbuttontext" />

</RelativeLayout>

这是我的活动

    package com.example.emeterfinalapp;

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

        import com.google.android.gms.common.GooglePlayServicesUtil;
        import com.google.android.gms.maps.GoogleMap;
        import com.google.android.gms.maps.SupportMapFragment;

        public class SelectLocation extends FragmentActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_location);
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
                                           GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

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

    }


}

我向我的项目提供了 google_play_services lib 的引用,在我的 lib 中添加了 google_play_service 和 android.support.v4 jar 文件....如果我仍然缺少任何内容,请指导....

我有 api 密钥,我已将其添加到 maifest 中,请参阅上面的内容,现在对其进行了编辑...

这是我的电话日志中的错误跟踪

  I/ActivityManager(  282): Displayed com.example.emeterfinalapp/.EmeterMainActivity:                +206ms
     I/ActivityManager(  282): Displayed com.example.emeterfinalapp/.EnterLocationActivity:      +224ms
     W/InputDispatcher(  282): channel '2c3dbfd0      com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~           Consumer closed input channel or an error occurred.  events=0x8
     E/InputDispatcher(  282): channel '2c3dbfd0      com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~      Channel is unrecoverably broken and will be disposed!
     W/InputDispatcher(  282): Attempted to unregister already unregistered input channel      '2c3dbfd0 com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity      (server)'
     W/InputDispatcher(  282): channel '2c504fb8      com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~      Consumer closed input channel or an error occurred.  events=0x8
     E/InputDispatcher(  282): channel '2c504fb8      com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~      Channel is unrecoverably broken and will be disposed!
     W/InputDispatcher(  282): Attempted to unregister already unregistered input channel      '2c504fb8 com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity      (server)'

呼...在挠了妈妈的头这么久之后我终于找到了解决方案 首先,我按照非常棒的文档,使用 DDMS 对真实设备进行了调试,然后我发现了以下错误

12-12 15:08:29.458: E/AndroidRuntime(26382): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.example.emeterfinalapp/com.example.emeterfinalapp.SelectLocation}:     android.view.InflateException: Binary XML file line #17: Error inflating class fragment

然后又写了几行代码后,出现了另一个引人注目的错误

12-12 15:08:29.458: E/AndroidRuntime(26382): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

然后我意识到我的 api 密钥代码是清单的子项,而不是上述错误指出的应用程序,然后我将清单纠正为以下内容

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


<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="16" />

  <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
 <permission
     android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
<uses-permission  android:name="com.example.emeterfinalapp.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"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

     <uses-library android:name="com.google.android.maps"/>
    <activity
        android:name="com.example.emeterfinalapp.EmeterMainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.emeterfinalapp.EnterLocationActivity"
        android:label="@string/title_activity_enter_location"
        android:parentActivityName="com.example.emeterfinalapp.EmeterMainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.emeterfinalapp.EmeterMainActivity" />
    </activity>

    <activity
        android:name="com.example.emeterfinalapp.SelectLocation"
        android:label="@string/title_activity_select_location"
        android:parentActivityName="com.example.emeterfinalapp.EnterMainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.emeterfinalapp.EnterMainActivity" />
    </activity>

     <meta-data
   android:name="com.google.android.maps.v2.API_KEY"
   android:value="my api key"/>
</application>

然后它就像变焦一样,一切都完美地工作...使用真实设备进行调试有很大帮助...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

谷歌地图 android api v2 应用程序崩溃 的相关文章

随机推荐

  • Android HTML 资源以及对其他资源的引用

    我想向我的 Android 项目添加一个 HTML 资源 并引用其他资源 主要是可绘制资源 我应该把它放在哪里以及如何从中引用其他资源 有没有一种特殊的方法可以将 HTML 资源传递给WebView Thanks html 文件以及所有可绘
  • java.lang.ClassCastException:java.math.BigInteger无法转换为java.lang.Long

    我想使用本机 sql 返回行数 但控制台说我java math BigInteger cannot be cast to java lang Long 怎么了 这是我的方法 public Long getNumRows Integer id
  • C# set/get 中的堆栈溢出错误[重复]

    这个问题在这里已经有答案了 周五 我正在处理一个应用程序的公共评论部分 当时我遇到了堆栈溢出错误 这让我很困惑 所以我想我应该寻求帮助 使用 堆栈溢出 这个表达来搜索网络有点弄巧成拙 在发送要添加到数据库的类的实例之前 我想对类中字段的 s
  • 在 C++ 中将 24 位整数(2 补码)转换为 32 位整数

    dataFile bin 是一个具有 6 字节记录的二进制文件 前 3 个 每条记录的字节包含纬度 最后 3 个字节包含 经度 每个 24 位值表示弧度乘以 0X1FFFFF 这是我一直在做的一项任务 我已经很多年没接触过 C 了 所以它需
  • Ubuntu 中使用 C/C++ 进行线路输入插孔感应

    这可能已经被问到死了 但我永远无法找到最终的解决方案 可能是出于充分的理由 无论如何 Ubuntu 我使用内核为2 6 38 8的Ubuntu 11 04 有什么方法可以检测是否插入了耳机 具体来说 我正在寻找 C C 解决方案来轮询我的
  • SQL - 查找所有可能的组合

    我需要帮助查找数据库中所有可能的值组合 例如我有这个表 ITEM SET Support I1 0 244999999 I2 0 274999999 I3 0 258333333 I4 0 103333333 我需要找到所有可能的组合 如下
  • PHP 解析 $_POST 数组?

    服务器向我发送以下格式的 POST 请求 POST array1 info1 info2 info3 info4 所以很自然地 我可以非常简单地提取信息 POST info 但是如何获取 array1 中的三个信息呢 我试过 POST ar
  • 如何在本地项目中为 JavaScript 库创建类型定义?

    我正在尝试使用N3打字稿项目中的库 自述文件中的示例 javascript 代码如下所示 const N3 require n3 const DataFactory N3 const namedNode literal defaultGra
  • 在 d3.js 中的 x 轴上以不同格式打印日期

    我正在使用 D3 js 构建此折线图 它工作正常 但我无法以缩写形式打印 x 轴上的月份 一月 二月 这是我如何解析日期的 var parseDate d3 time format m Y parse x 轴的代码 var xAxis d3
  • 使用 gridExtra 绘制多个格子图

    有一种非常方便的方法来绘制多个图表 那就是 gridExtra grid arrange grid arrange plot1 plot2 plot3 plot4 plot5 plot6 plot7 plot8 plot9 ncol 3 上
  • WlanOpenHandle 失败,错误代码 1062

    我正在使用本机 Wifi Api 获取 Windows 8 计算机上的 ssid 但 WlanOpenHandle 调用始终失败 错误代码为 1062 有任何帮助吗 注意 Windows 8 上没有 wzc 服务 正如OP所确认的 错误的直
  • Google Cloud Shell 使用的是project=cloud-devshell-dev 而不是我的实际项目,找不到启用的API

    我创建了一个 GCP 项目来使用视频智能 API 我在项目上启用了 API 并启动了 Cloud Shell 然后我复制了代码github并按照自述文件的说明进行操作 但是 当我尝试运行时faces py我收到此错误消息 StatusCod
  • R 中数据表的奇怪情况,列名混合

    所以我创建了这个变量mc split device在数据表内称为mc with devices 但是 如果我输入mc with devices mc split我得到了列的值mc split device虽然我从未创建过任何具有该名称的变量
  • 严重:无法初始化 Jenkins [已关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 我已经在 Linux 上安装了 jenkins 但是当我尝试启动服务器时 它出现
  • MFC 中的 libmodbus

    我正在尝试将 libmodbus 提供的 modbus 库集成到 Visual Studio 2010 中的自定义 MFC 项目中 到目前为止我所遵循的步骤如下 1 我在 Visual Studio 2010 中创建了项目 如下面的快照所示
  • 逼近非参数三次贝塞尔曲线

    近似三次贝塞尔曲线的最佳方法是什么 理想情况下 我想要一个函数 y x 它可以给出任何给定 x 的精确 y 值 但这将涉及求解每个 x 值的三次方程 这对于我的需求来说太慢了 并且可能存在数值稳定性问题以及这种方法 Would this是一
  • CMUSphinx PocketSphinx - 识别所有(或大量)单词

    在我尝试使用 Android 版 PocketSphinx 之前 我使用了 Google 的语音识别 API 我不需要设置搜索名称或字典文件 它只是识别了所说的每一个字 现在 在 PocketSphinx 中 我需要这样做 但我只能找到如何
  • mongo-php-library 和 MongoDB 驱动程序有什么区别

    mongo php library 和 MongoDB 驱动程序有什么区别 它们在性能和功能方面有何不同 优缺点都有什么 我们目前在生产中使用 mongo php library 如下所示 connection new MongoDB Cl
  • 当用户到达页面底部时隐藏 div

    我想在用户滚动并到达页面底部时隐藏 div 元素 并在用户向上滚动时再次显示它 例如 考虑以下名为 nav 的导航栏 HTML div class nav div CSS nav width 100 height 50px position
  • 谷歌地图 android api v2 应用程序崩溃

    我正在使用 Eclipse helios 和 Android 4 1 2 我已遵循以下文档https docs google com document pub id 19nQzvKP CVLd7 VrpwnHfl AE9fjbJySowON