Mapview 示例在启动时崩溃
我正在尝试地图视图示例。但它在活动启动时崩溃了。我的构建目标是 Google API 2.1 版。它在设备和模拟器上都会崩溃。另外,我无法覆盖方法 isRouteDisplayed。这是我的代码
package com.sandy.hellogooglemaps;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.MapView;
public class HelloGoogleMaps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
//@Override
protected boolean isRouteDisplayed() {
return false;
}
}
,我的清单文件是
<application android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name">
<activity android:name=".HelloGoogleMaps"
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" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
我的布局 xml 是
i am trying mapview example. But it is crashing on activity launch. my build target is Google API for version 2.1. it is crashing on both device and emulator. Also, i am not able to Override method isRouteDisplayed. here is my code
package com.sandy.hellogooglemaps;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.MapView;
public class HelloGoogleMaps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
//@Override
protected boolean isRouteDisplayed() {
return false;
}
}
and my manifest file is
<application android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name">
<activity android:name=".HelloGoogleMaps"
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" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
my xml for layout is
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将
extends Activity
更改为extends MapActivity
you have to change
extends Activity
toextends MapActivity
您应该扩展MapActivity,而不是Activity。
另请确保您已向 MapView 提供了有效的 Google 地图 Api 密钥:
http://code.google.com /intl/iw-IL/android/add-ons/google-apis/mapkey.html
我希望它有帮助。
You should extend MapActivity, not Activity.
Also make sure that you have provided to your MapView valid Google Maps Api Key:
http://code.google.com/intl/iw-IL/android/add-ons/google-apis/mapkey.html
I hope it helps.