首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

从assets中读取的文件转化成了Bit地图,Canvas绘制时报空指针。代码.

2012-09-17 
从assets中读取的文件转化成了Bitmap,Canvas绘制时报空指针。代码.....private Bitmap getImageFromAssetsF

从assets中读取的文件转化成了Bitmap,Canvas绘制时报空指针。代码.....
private Bitmap getImageFromAssetsFile(String fileName)  
{  
Bitmap image = null;  

AssetManager am = getResources().getAssets();  

try {  

InputStream is = am.open(fileName);  
image = BitmapFactory.decodeStream(is);  
is.close();  
}  
catch (IOException e) {

e.printStackTrace();  
}  

return image;  
 
}

[解决办法]
这段代码没什么问题。。你是怎么调用的,传入的文件名对吗?
[解决办法]
空指针就容易多了,你看哪个对象 空的,
InputStream is = am.open(fileName); 文件名正确否
 image = BitmapFactory.decodeStream(is); 解码成功否?Z

有没有异常信息呢?

热点排行