Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso: Unrecognized type of request for HTTP scheme

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.

like image 725
Rohit Arya Avatar asked Sep 12 '16 18:09

Rohit Arya


1 Answers

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!

like image 106
Gabriel Piffaretti Avatar answered Nov 14 '22 23:11

Gabriel Piffaretti