找不到文件java.io.FileNotFoundException:打开失败:ENOENT(没有这样的文件或目录)GLIDE?

时间:2019-10-22 11:23:17

标签: java android camera imageview glide

我将图像保存在android / data / com.myappliction / files / Pictures / file.jpg内的文件夹中。每当我尝试使用滑行打开时。我得到以下日志。

代码:

public class profile extends AppCompatActivity {
    ImageView imageView;
    File file = new File("Android/data/com.example.cogniace/files/Pictures/profile.jpg");
    private static final String TAG = profile.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
       imageView = findViewById(R.id.imageView);

        Glide.with(this)
                  .load(file)

                .placeholder(R.drawable.ic_sync_black_24dp)
                //.error(R.drawable.camera_icon)
                .into(imageView);

例外:

2019-10-22 16:40:05.337 30115-30115/com.example.cogniace W/Glide: Load failed for Android/data/com.example.cogniace/files/Pictures/profile.jpg with size [1002x1506]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    java.io.IOException(File unsuitable for memory mapping)
    java.io.FileNotFoundException(Android/data/com.example.cogniace/files/Pictures/profile.jpg (No such file or directory))
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.nio.ByteBuffer, LOCAL
    There was 1 cause:
    java.io.IOException(File unsuitable for memory mapping)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.IOException: File unsuitable for memory mapping
      Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(Android/data/com.example.cogniace/files/Pictures/profile.jpg (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: Android/data/com.example.cogniace/files/Pictures/profile.jpg (No such file or directory)
      Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: ENOENT (No such file or directory))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
2019-10-22 16:40:05.338 30115-30115/com.example.cogniace I/Glide: Root cause (1 of 3)
    java.io.IOException: File unsuitable for memory mapping
        at com.bumptech.glide.util.ByteBufferUtil.fromFile(ByteBufferUtil.java:38)
        at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:61)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:431)
2019-10-22 16:40:05.339 30115-30115/com.example.cogniace I/Glide: Root cause (2 of 3)
    java.io.FileNotFoundException: Android/data/com.example.cogniace/files/Pictures/profile.jpg (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:231)
        at java.io.FileInputStream.<init>(FileInputStream.java:165)
        at com.bumptech.glide.load.model.FileLoader$StreamFactory$1.open(FileLoader.java:142)
        at com.bumptech.glide.load.model.FileLoader$StreamFactory$1.open(FileLoader.java:139)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:71)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:408)
        at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:130)
        at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:66)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:431)
2019-10-22 16:40:05.341 30115-30115/com.example.cogniace I/Glide: Root cause (3 of 3)
    java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
        at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:313)
        at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:211)
        at com.bumptech.glide.load.model.FileLoader$FileDescriptorFactory$1.open(FileLoader.java:166)
        at com.bumptech.glide.load.model.FileLoader$FileDescriptorFactory$1.open(FileLoader.java:163)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:71)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:408)
        at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:130)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:76)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:408)
        at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailed(SourceGenerator.java:130)
        at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:66)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:431)
2019-10-22 16:40:10.390 30115-30177/com.example.cogniace V/FA: Inactivity, disconnecting from the service

1 个答案:

答案 0 :(得分:0)

您需要传递图片的URI。试试这个:-

 Glide.with(this)
      .load(imageUri)

OR

Glide.with(context)
    .load(new File(fileUri.getPath()))