Picasso: Unrecognized type of request for HTTP scheme

南楼画角 提交于 2019-12-01 18:03:31

问题


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.


回答1:


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!




回答2:


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



来源:https://stackoverflow.com/questions/39456858/picasso-unrecognized-type-of-request-for-http-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!