Glide在加载无效网址时崩溃了

时间:2019-05-02 09:50:56

标签: android android-glide

在开发应用程序时,意外将无效的URL传递给了Glide。它使我的应用崩溃了。

共享我的代码:

val file = requestManager.downloadOnly().load(imageUrl).listener(requestListener).submit().get()

共享崩溃日志:

 java.lang.Error: java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://imageSamples/sampleimage.jgp)
 call GlideException#logRootCauses(String) for more detail
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1139)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:760)
 Caused by: java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://imageSamples/sampleimage.jgp)
 call GlideException#logRootCauses(String) for more detail
    at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:205)
    at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:108)
    at com.sample.app.Manager.cacheImage(Manager.kt:69)
    at com.sample.app.Manager.access$cacheImage(Manager.kt:19)
    at com.sample.app.Manager$updateImageCache$1.run(Manager.kt:46)
    at io.fabric.sdk.android.services.concurrency.AsyncTask$SerialExecutor$1.run(AsyncTask.java:254)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        ... 2 more
 Caused by: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.io.FileNotFoundException(https://imageSamples/sampleimage.jgp)
 call GlideException#logRootCauses(String) for more detail

我为防止应用程序崩溃而进行的操作是try-catch。但是我不是很高兴在代码中使用try catch。

    try {
        val file = requestManager.downloadOnly().load(imageUrl).listener(requestListener).submit().get()
    } catch (e: Exception) {
        e.printStackTrace()
    }

是否有更好的方法来处理?像Glide的某些API方法一样?

1 个答案:

答案 0 :(得分:1)

这可能是由于找不到URL引起的。

var columns= [
            { "width": "80px", "targets": 0 },
            { "width": "120px", "targets": 1 },
            { "width": "120px", "targets": 2 }, 
            { "width": "120px", "targets": 3 },
            { "width": "120px", "orderable": false, "targets": 4 },
            { "width": "120px", "targets": 5 },
            { "width": "100px", "targets": 6 },
            { "width": "110px", "targets": 7 },
            { "width": "150px", "orderable": false, "targets": 8 },
            { "width": "150px", "orderable": false, "targets": 9 },
            { "width": "150px", "orderable": false, "targets": 10 },
            { "width": "150px", "orderable": false, "targets": 11 }
        ];

        var table = $('#activities-table').DataTable({
            "searching": { "regex": true },
            "bLengthChange": false,
            "scrollY":"500px",
            "scrollX":"300px",
            "scrollCollapse": true,
            "paging": false,
            "autoWidth": false,
            "processing": true,
            "serverSide": true,
            "autoWidth": true,
            "ajax": {
                url: "activities-data.php",
                type: "POST",
                "dataType": "json",
                data: {salesman:salesman, startdate:startdate, enddate:enddate, supervisor:supervisor},
                "complete": function(response) {
                    console.log(response);
                }
            },
            "columnDefs": columns,
            "language": {
                "emptyTable": "No data available in table",
                "zeroRecords": "No data available in table",
                "info": "Showing <b>_START_</b> to <b>_END_ of _TOTAL_</b> entries",
                "paginate": {
                    "first":      "First",
                    "last":       "Last",
                    "next":       "Next",
                    "previous":   "Previous"
                },
                search: "_INPUT_",
                searchPlaceholder: "Search..."
            },
            dom: 'Bfrtip',
            buttons: [
                'csv', 'excel', 'pdf'
            ]
        });

URL java.io.FileNotFoundException(https://firebaestorage.googleapis.com/v0/b/fir-config-f8c4e.appspot.com/o/resized.png?alt=media&token=5ac525a2-b195-467b-b52a-7c1619aa158d) 以上可能是错误的,因为firebaestorage.googleapis.com中缺少s

相关问题