Android 中的地图演示应用程序无法正常工作

发布于 2024-10-17 09:24:40 字数 2434 浏览 2 评论 0原文

我正在 Android 中尝试我的第一个地图应用程序,但是当我运行该应用程序时,模拟器中会显示一条消息:

“应用程序应用程序名称意外停止”

以下是代码:

demomaps.java

    package com.tutorial.demomaps;

//import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.android.maps.*;

public class demomaps extends MapActivity {
    /** Called when the activity is first created. */
    LinearLayout linearLayout;
    MapView mapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapView = (MapView)findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        setContentView(R.layout.main);
    }

    @Override
    protected boolean isRouteDisplayed()
    {

        return false;
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="00OHG4fs5JkMMURfVtKse-D3wVv1BImlK_3zz3g">   

</com.google.android.maps.MapView>
</RelativeLayout>   

AndroidManifest.xml

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


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".demomaps"
                  android:label="@string/app_name">
            <intent-filter>
                <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"></uses-library>
    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

I am trying my first map application in Android but when I run the application, a message in the emulator is displayed saying

"the application APPLICATION NAME stopped unexpectedly"

Here is the code:

demomaps.java

    package com.tutorial.demomaps;

//import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.android.maps.*;

public class demomaps extends MapActivity {
    /** Called when the activity is first created. */
    LinearLayout linearLayout;
    MapView mapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapView = (MapView)findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        setContentView(R.layout.main);
    }

    @Override
    protected boolean isRouteDisplayed()
    {

        return false;
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="00OHG4fs5JkMMURfVtKse-D3wVv1BImlK_3zz3g">   

</com.google.android.maps.MapView>
</RelativeLayout>   

AndroidManifest.xml

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


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".demomaps"
                  android:label="@string/app_name">
            <intent-filter>
                <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"></uses-library>
    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你的占有欲 2024-10-24 09:24:40

Sid,

代码对我来说看起来不错。确保模拟器正在使用 Google API。如果没有,请创建新的模拟器来进行测试。

Sid,

Code looks ok to me. Make sure emulator is using the Google API's. If not, create new emulator that does for testing.

终难愈 2024-10-24 09:24:40

我让应用程序运行起来,首先我再次从 Google 获取密钥并将其放入 main.xml(再次),然后将权限

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>

android.permission.INTERNET 添加到 AndroidManifest.xml 并构建该项目并运行它。这对我的情况有效,可能会帮助其他遇到同样问题的人。

谢谢,
席德

I got the application running, first I got the the Key form Google again and placed it in main.xml (again) and I added permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>

along with android.permission.INTERNET to the AndroidManifest.xml and built the project and ran it. This worked in my case, might help other people who get the same issue.

Thanks,
Sid

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文