Android 中的地图演示应用程序无法正常工作
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
我让应用程序运行起来,首先我再次从 Google 获取密钥并将其放入 main.xml(再次),然后将权限
与
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
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