I am trying to start a simple map activity that displays a map an a couple of markers using osmdroid-android-3.0.7 library. The code worked under an older version (1.10). I am getting the following error: 02-03 15:14:30.574: E/AndroidRuntime(10277): Caused by: java.lang.IllegalArgumentException: Resource not found: marker_default.png
When I unzipped the jar file I can see a list of icons in the top level directory and one of them is indeed marker_default.png. This is the snippet of the code:
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);
}
}
When I tried to use a simple overlay and therefore did not set any icons for the marker then I got the same error except it referred to person.png (that icon is also in the unzipped jar file). I have added the jar file via project properties and can access the api just fine.
Why can't I access the icons?
BTW, I tried to copy the icons into my project but I got the same error.
Thanks, Ania
I had the same problem - in the latest jar (3.0.8) the issue is fixed.
There is an issue in the bug tracker which I think has a solution for this. Have not had the issue myself I provide my own bitmap. I do remember all the proxy stuff being confusing and troublesome.
来源:https://stackoverflow.com/questions/9135284/cannot-access-resource-icons-when-running-with-osmdroid-android-3-0-7