Picasso: Unrecognized type of request for HTTP sch

2019-02-25 07:14发布

I am loading images synchronously to display notification once the image is loaded.

bitmap = picasso.load(imageUrl).get();

It was working fine but today I got an exception:

Fatal Exception: java.lang.IllegalStateException: Unrecognized type of request: Request{
http://www.fulbori.com/mp/resources/image/19/17/e.jpg}
       at com.squareup.picasso.BitmapHunter$2.load(BitmapHunter.java:66)
       at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
       at com.squareup.picasso.RequestCreator.get(RequestCreator.java:396)
       at com.jumbotail.app.utils.JtImageLoader.loadImageSync(JtImageLoader.java:397)
       at com.jumbotail.app.notifs.JumboGcmIntentService.readInboundIntent(JumboGcmIntentService.java:213)
       at com.jumbotail.app.notifs.JumboGcmIntentService.buildNotification(JumboGcmIntentService.java:273)
       at com.jumbotail.app.notifs.JumboGcmIntentService.onHandleIntent(JumboGcmIntentService.java:49)
       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:174)
       at android.os.HandlerThread.run(HandlerThread.java:60)

I understand that this error is thrown by Picasso when no request handlers can handle the request.

Now, as per the Uri scheme of the request (which is http) canHandleRequest(Request data) method of NetworkRequestHandler should have returned true.

But all the request handlers returned false including NetworkRequestHandler. Thus, ERRORING_HANDLER was returned by Picasso resulting into the exception : IllegalStateException("Unrecognized type of request: " + request).

Is there any other explanation to this exception?

EDIT: I have also raised an issue in Picasso.

2条回答
劫难
2楼-- · 2019-02-25 07:43

In particular I had this error because the URL I was getting, as the error mentions, is not a valid URL that a handler can use. In particular, the URL string had spaces before the "http", like:

" http://example.com/image.jpg".

So I just had to call trim() on the url string, before loading it with Picasso, and worked great!

查看更多
Ridiculous、
3楼-- · 2019-02-25 07:47

You can also get this if the path you pass Picasso is missing the hostname and scheme :-)

查看更多
登录 后发表回答