Java Android:SkipageDecoder::Factory在从图库检索图像时返回null

Java Android:SkipageDecoder::Factory在从图库检索图像时返回null,java,android,image,android-intent,gallery,Java,Android,Image,Android Intent,Gallery,前几天,当我试图从图库(或动作精选)中获取图像时,遇到了这个问题 结果表明,这个问题是由于某些原因导致文件损坏,因此Android将其大小视为0,这将导致日志中出现上述错误,如果您尝试显示图像,它将变为空白 查看下面的帖子,了解我是如何解决此问题的。这也适用于通过其他方式检索的图像,只要您将其视为文件或可以控制其大小 就这么做吧 File photo = new File(path_to_your_file); //Even if the size is 0, t

前几天,当我试图从图库(或动作精选)中获取图像时,遇到了这个问题

结果表明,这个问题是由于某些原因导致文件损坏,因此Android将其大小视为0,这将导致日志中出现上述错误,如果您尝试显示图像,它将变为空白


查看下面的帖子,了解我是如何解决此问题的。

这也适用于通过其他方式检索的图像,只要您将其视为文件或可以控制其大小

就这么做吧

        File photo = new File(path_to_your_file);
        //Even if the size is 0, the file itself isn't null, so you need to check for this as well
        if(photo!=null){
            Double size = (double) photo.length();
            //transform the size from bytes to kb, for reasons.
            size = size/1024;
            //I can't recall a single instance when a file has a negative size, but lets just throw it in there to be sure.
            if(size<=0){
                Log.i("this image","ain't good");
            }else{
                 //do whatever you normally do with your file
            }
        }
File photo=新文件(指向您的文件的路径);
//即使大小为0,文件本身也不是空的,因此您也需要检查是否存在这种情况
如果(照片!=null){
Double size=(Double)photo.length();
//出于某些原因,请将大小从字节转换为kb。
大小=大小/1024;
//当一个文件的大小为负时,我想不起有哪一个实例,但让我们把它放在那里以确定。
如果(尺寸)