【发布时间】:2012-06-06 20:07:14
【问题描述】:
由于我发布了与该问题不同的代码,因此我已经解决了关于此问题的最后一个问题,因此我将使用正确的代码再次尝试...
所以这就是交易,我一直在使用适用于 Android 的 GoogleMaps API 运行一些测试,当我尝试使用我的一张图像在我的地图上设置 CustomItemizedOverlay 时,我注意到当我使用 getDrawable访问我的图像它返回 null 即使 eclipse 本身显示我的图像在我使用 ctrl+backspace 选择我希望访问的可绘制对象时在那里:/
因为这个,我已经好几个小时在墙上钻了空子。关于这里有什么问题的任何线索?
提前致谢:)
PS:打印显示当我使用 ctrl + backspace http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png 时,eclipse 在资源中显示我的图像@
代码:
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;
}
}
【问题讨论】:
-
您是否在图像中使用了 .png、.jpg 或 .gif 以外的扩展名?它可能无法识别其他扩展类型。 http://developer.android.com/guide/topics/resources/drawable-resource.html
标签: android resources nullpointerexception getresource