Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 资产中的BitmapFactory.decode文件不';t工作(FileNotFindException)_Android_Bitmapfactory_Android Assets - Fatal编程技术网

Android 资产中的BitmapFactory.decode文件不';t工作(FileNotFindException)

Android 资产中的BitmapFactory.decode文件不';t工作(FileNotFindException),android,bitmapfactory,android-assets,Android,Bitmapfactory,Android Assets,我不知道为什么decodeFile在参数指向资产文件夹中的文件时不起作用 // Load images from the file path String[] dir = null; try { dir = GenericMainContext.sharedContext.getAssets().list("drawable"); // dir Log => [ic.png, ic_info_dark.png, ic_launcher

我不知道为什么
decodeFile
参数指向资产文件夹中的文件时不起作用

     // Load images from the file path
    String[] dir = null;
    try {
        dir = GenericMainContext.sharedContext.getAssets().list("drawable");
       // dir Log => [ic.png, ic_info_dark.png, ic_launcher_default.png]
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    for (String uri : dir){ 
        // do your stuff here
        if (uri!=null) {
            Bitmap bitmap = null;
            try {
                bitmap = BitmapFactory.decodeFile("file:///android_asset/drawable/"+uri);               } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

有什么解释吗?

file:///android_asset/
由WebView用于加载资产。要以编程方式加载资产,请使用
getAssets()
方法,该方法在
上下文
对象(如
活动
)上返回一个
AssetMAnager
open(filename)
将向您的资产文件返回
InputStream
。下面将从
活动
中的资产文件
文件名
创建一个
位图

BitmapFactory.decodeStream(getAssets().open(fileName))

有什么解释吗?是,
fileName
在资产中不存在……我检查了
fileName
exist;)不,它不。。。我有更多的代表。。。我赢了。。。或者你会证明它的存在…看这里不要用
file:///android_asset/
,使用
getAssets().open(“drawable/”+uri)
@abdellahn未更改相同结果位图
null
不使用
file:///android_asset/
,使用
getAssets().open(“drawable/”+uri)
@Abdellah