我想使用osmdroid-android-3.0.7庫啓動一個顯示地圖的幾個標記的簡單地圖活動。代碼在舊版本(1.10)下工作。我收到以下錯誤: 02-03 15:14:30.574:E/AndroidRuntime(10277):導致:java.lang.IllegalArgumentException:資源未找到:marker_default.png使用osmdroid-android-3.0.7運行時無法訪問資源圖標
當我解壓縮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就好了。
爲什麼我無法訪問圖標?
順便說一句,我試圖將圖標複製到我的項目,但我得到了同樣的錯誤。
感謝,阿尼亞
我報告了你提到的問題,與這個問題完全一樣,所以我會說這絕對是osmdroid中的一個錯誤:(解決方法是按照問題中的解釋修補osmdroid或提供自己的圖標(我相信通過實現代理的東西) – Nico 2012-02-06 03:12:18
謝謝,現在我將使用一個較早的版本,希望這些錯誤很快就會被修復 – user1188398 2012-02-06 15:43:58