getDrawable返回null [英] getDrawable returning null

查看:654
本文介绍了getDrawable返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我已经打掉我对于这件事的最后一个问题,由于张贴有关的问题,我要去用正确的code再次尝试从一个不同的code ...

Since i've busted my last question regarding this matter due to posting a different code from the one regarding the problem i'm going to try again with the right code...

所以这里的交易,我一直在运行有Android版谷歌地图API的一些测试,当我试图建立在使用我的照片我的一个映射的CustomItemizedOverlay,我注意到,当我使用getDrawable到访问我的形象,它返回null即使寿蚀本身就说明了我,我的形象是存在的,当我选择它可绘制我希望接取时,使用Ctrl +退格键:/

So here's the deal, I've been running some tests with GoogleMaps API for Android and when i was trying to set up an CustomItemizedOverlay on my map using one of my images, i've noticed that when i was using getDrawable to access my image it was returning null even tho eclipse itself shows me my image is there when i use ctrl+backspace when selecting which drawable i wish to acess :/

我一直在破坏我的头穿墙的,因为这几个小时。对什么是错在这里任何线索?

I've been busting my head through the wall for hours because of this. Any clues on what's wrong here?

在此先感谢:)

PS:打印可见日食显示我的资源中的图像时,我用ctrl + Backspace键的 http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png

PS: print showing that eclipse shows my image inside resources when i use ctrl + backspace http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png

code:

import java.util.List;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MapHandlerActivity extends MapActivity {


private MapView mapView;
private static final int latitudeE6 = 37985339;
private static final int longitudeE6 = 23716735;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    setContentView(R.layout.maphandler);

    mapView = (MapView) findViewById(R.id.map_view);      
    mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Resources res = this.getResources();
    Drawable drawable = res.getDrawable(R.drawable.android_tiny_image);
    CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
    GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
    OverlayItem overlayItem = new OverlayItem(point, "Olá", "Estou em Athena, Grécia!");

    itemizedOverlay.addOverlay(overlayItem);
    mapOverlays.add(itemizedOverlay);

    MapController mapController = mapView.getController();

    mapController.animateTo(point);
    mapController.setZoom(6);
}
@Override
protected boolean isRouteDisplayed() {
    return true;
}

}

推荐答案

尝试具有所有绘制质量文件夹(可绘制-HDPI /绘制-LDPI等。)

Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)

可能是你使用模拟器或设备有不同的密度,并试图从另一个文件夹拉的图像。

Could be that the emulator or device your using has a different density and is trying to pull images from another folder.

这篇关于getDrawable返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆