使用 osmdroid-android-3.0.7 运行时无法访问资源图标

发布于 2025-01-02 02:43:20 字数 3368 浏览 3 评论 0原文

我正在尝试启动一个简单的地图活动,使用 osmdroid-android-3.0.7 库显示地图和几个标记。该代码在旧版本(1.10)下运行。我收到以下错误: 02-03 15:14:30.574:E / AndroidRuntime(10277):引起:java.lang.IllegalArgumentException:找不到资源: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。

为什么我无法访问图标?

顺便说一句,我尝试将图标复制到我的项目中,但遇到了同样的错误。

谢谢,阿尼娅

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅唱ヾ落雨殇 2025-01-09 02:43:20

我遇到了同样的问题 - 在最新的 jar (3.0.8) 中,问题已得到解决。

I had the same problem - in the latest jar (3.0.8) the issue is fixed.

筱武穆 2025-01-09 02:43:20

错误跟踪器中存在一个问题,我认为该问题与对此的解决方案。我自己没有遇到过这个问题,我提供了我自己的位图。我确实记得所有代理的东西都是令人困惑和麻烦的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文