我正在尝试启动一个简单的地图活动,该活动使用 osmdroid-android-3.0.7 库显示地图和几个标记。该代码在旧版本(1.10)下工作。我收到以下错误:02-03 15:14:30.574: E/AndroidRuntime(10277): Caused by: java.lang.IllegalArgumentException: Resource not found: marker_default.png
当我解压缩 jar 文件时,我可以在顶级目录中看到一个图标列表,其中一个确实是 marker_default.png。这是代码片段:
public class MapDisplay extends Activity
{
private MapView mapView;
private ResourceProxy resProxy;
private ItemizedOverlay<OverlayItem> locationOverlay;
public void onCreate(final Bundle savedState)
{
super.onCreate(savedState);
resProxy = new DefaultResourceProxyImpl(getApplicationContext());
final RelativeLayout rl = new RelativeLayout(this);
mapView = new MapView(this, 256);
mapView.setBuiltInZoomControls(true);
mapView.getController().setZoom(6);
mapView.getController().setCenter(new GeoPoint(51500000, 5400000));
rl.addView(mapView, new RelativeLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
OverlayItem o1 = new OverlayItem("Location 1", "Comment",
new GeoPoint(51500000, 5400000));
o1.setMarker(getResources().getDrawable(R.drawable.icall));
items.add(o1);
OverlayItem o2 = new OverlayItem("Location 2", "Comment",
new GeoPoint(52500000, 5500000));
o2.setMarker(getResources().getDrawable(R.drawable.icall));
items.add(o2);
this.locationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>()
{
@Override
public boolean onItemSingleTapUp(final int index,
final OverlayItem item)
{
Toast.makeText(
MapDisplay.this,
"Item '" + item.mTitle + "' (index=" + index
+ ") got single tapped up", Toast.LENGTH_LONG).show();
return true; // We 'handled' this event.
}
@Override
public boolean onItemLongPress(final int index,
final OverlayItem item)
{
Toast.makeText(
MapDisplay.this,
"Item '" + item.mTitle + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
}
}, resProxy);
this.mapView.getOverlays().add(this.locationOverlay);
mapView.invalidate();
this.setContentView(rl);
}
}
当我尝试使用简单的覆盖并因此没有为标记设置任何图标时,我得到了相同的错误,除了它引用了 person.png (该图标也在解压缩的 jar 文件中)。我已经通过项目属性添加了 jar 文件,并且可以正常访问 api。
为什么我无法访问图标?
顺便说一句,我试图将图标复制到我的项目中,但我得到了同样的错误。
谢谢, 安妮娅