Java 无法将位图转换为可绘制,为什么会出现此错误?
我花了大约3个小时试图弄明白这一点,它似乎很简单,但我似乎无法解决它!有人能帮帮我吗!我只想让它显示一个来自drawable resources文件夹的图像。它说“无法从位图转换为可绘制” 嗯,这是对的——不会延伸。我没有做过任何Android开发,但听起来你想要一个: 嗯,这是对的——不会延伸。我没有做过任何Android开发,但听起来你想要一个:Java 无法将位图转换为可绘制,为什么会出现此错误?,java,android,bitmap,drawable,Java,Android,Bitmap,Drawable,我花了大约3个小时试图弄明白这一点,它似乎很简单,但我似乎无法解决它!有人能帮帮我吗!我只想让它显示一个来自drawable resources文件夹的图像。它说“无法从位图转换为可绘制” 嗯,这是对的——不会延伸。我没有做过任何Android开发,但听起来你想要一个: 嗯,这是对的——不会延伸。我没有做过任何Android开发,但听起来你想要一个: 您需要将您的资源作为可提取资源: if(type.equals("restaurant")) { this.marker = conte
您需要将您的资源作为可提取资源:
if(type.equals("restaurant"))
{
this.marker = context.getResources().getDrawable(R.drawable.restaurant);
} else {
// marker would get no value without that else case - not allowed if you declare it final
this.marker = null;
}
您需要将您的资源作为可提取资源:
if(type.equals("restaurant"))
{
this.marker = context.getResources().getDrawable(R.drawable.restaurant);
} else {
// marker would get no value without that else case - not allowed if you declare it final
this.marker = null;
}
更改此项:
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.restaurant);
this.marker = bmp;
为此:
Drawable d = context.getResources().getDrawable(R.drawable.restaurant);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
this.marker = d;
更改此项:
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.restaurant);
this.marker = bmp;
为此:
Drawable d = context.getResources().getDrawable(R.drawable.restaurant);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
this.marker = d;
我只是想说我试过了,结果在“public PlaceOverlayItem(上下文上下文,位置p,字符串类型){super(p.getGeoPoint(),p.getName(),p.getFormatted_address())”中出现错误“空白的最终字段标记可能尚未初始化”这是一个不同的错误-在你的
if
之后放置一个else this.marker=null
所以marker
总是会得到一些值我只是想说我试过了,我在“public PlaceOverlayItem(上下文,placep,字符串类型)”中得到了错误“空白的最终字段标记可能尚未初始化”{super(p.getGeoPoint(),p.getName(),p.getFormatted_address());“这是一个不同的错误-在if
放置之后,否则this.marker=null
因此marker
将始终获得一些值我这样做了,但是我在public PlaceOverlayItem(上下文,Place p,String type)上得到了一个错误,它说“空白最终字段标记可能尚未初始化”。感谢您的帮助。我这样做了,但在public PlaceOverlayItem(上下文上下文、位置p、字符串类型)上出现错误,上面写着“空白最终字段标记可能尚未初始化”。感谢您的帮助。我这样做了,但在public PlaceOverlayItem上出现错误(上下文上下文,位置p,字符串类型),上面写着“空白的最终字段标记可能尚未初始化”。感谢您的帮助。我这样做了,但是我在public PlaceOverlayItem(上下文上下文,位置p,字符串类型)上发现一个错误,上面写着“空白的最终字段标记可能尚未初始化”。谢谢您的帮助。