I'm on Android Studio 4.1.3 (last release). I'm using the Android Volley library and I'm trying to retrieve an image from and API via ImageRequest. The URL that I'm using is the following one:
private String skinUrl = "http://crafatar.com/renders/body/680f95cff25d4f178fea90e2c003bebf.png?size=512&overlay&scale=7"
While using this url in the method
private void requestImage() {
RequestQueue requestQueue = Volley.newRequestQueue(this);
ImageRequest imageRequest = new ImageRequest(skinUrl, response -> skin.setImageBitmap(response),
0,
0,
ImageView.ScaleType.CENTER_CROP,
null,
error -> {
});
requestQueue.add(imageRequest);
}
I get this error message
NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.NetworkUtility.shouldRetryException(NetworkUtility.java:164)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:145)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
Caused by: java.net.MalformedURLException: no protocol:
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:498)
at java.net.URL.<init>(URL.java:447)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:82)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:104)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
I've also tried to use the method URLEncoder
skinUrl = URLEncoder.encode(skinUrl);
but the result is the same.
The problem is only appening with the ImageRequest, because I'm also retriving json data from another API.
simple bro use glide image loading library
because its top of android and fast and efficient for image loading just you have to put your image URL and image is load but you have to apply internet permission in manifest.
visit doc - https://github.com/bumptech/glide
Related
When I used volley to load data in android,I have a trouble.I used volley load googlemaps.
This is url:
http://maps.google.com/maps/api/geocode/json?address=No%204,%20Ng%C3%B5%20151B%20Th%C3%A1i%20H%C3%A0,%20L%C3%A1ng%20H%E1%BA%A1,%20%C4%90%E1%BB%91ng%20%C4%90a,%20H%C3%A0%20N%E1%BB%99i,%20Vietnam
1.In device >5.0.Volley loads it.
2.In device <5.0 like this: AsusZ002-Android:4.4.2,Htc-Android:4.2.2.Volley can't load it.
The bug is:
"Unexpected response code 400 for http://maps.google.com/maps/api/geocode/json?address=No%204,%20Ngõ%20151B%20Thái%20Hà,%20Láng%20Hạ,%20Đống%20Đa,%20Hà%20Nội,%20Vietnam"
Although a paste in website responses as json success.
Can you answer my questions?Thanks for having look at it.
Try to use URL encoder before loading it like so :
String url = http://maps.google.com/maps/api/geocode/json?address=No%204,%20Ng%C3%B5%20151B%20Th%C3%A1i%20H%C3%A0,%20L%C3%A1ng%20H%E1%BA%A1,%20%C4%90%E1%BB%91ng%20%C4%90a,%20H%C3%A0%20N%E1%BB%99i,%20Vietnam;
String formattedUrl = URLEncoder.encode(url, "utf-8");
i'm trying to call an api in my application
i've the following url template
test-test.domainname.com/feeds/json/v3/attribute/attribute
i'm using retrofit 2
but i get the following fatal exception
Illegal URL: test-test.domainname.com
and this is my interface
public interface Iinterface{
#GET("feeds/json/v3/attribute/"+attribute)
Call<ArrayList<result>>getresult();
}
can someone help me with this problem ...
my base URL is here: http://myapiname.azurewebservices.net
and feed method is like that :
public interface Iinterface{
#GET("/feeds/json/v3/attribute/"+attribute)
Call<ArrayList<result>>getresult();
}
And working perfectly. Please add http or https and try again
You do not have a protocol section. Prepend http:// or https:// depending on which applies to your url --
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://test-test.domainname.com")
// ... other retrofit options
.build();
In my case,
my base url contained space character. (eg. http://myapiname.azure webservices.net )
I fixed this Error by removing space in my base URL.
Illegal URL Exception in retrofit is triggered when your passed url is
not really existed or not fix with url standard.
By mistake, I provided empty string to baseUrl() so because of this i was getting java.lang.IllegalArgumentException: Illegal URL exception.
I have a set url (ex: http://mywebsite.com/cawn28xd/user_avatar) I call for imageloading that redirects to another link that may or may not be different.
I want to be able to either intercept the 302 redirect and grab the url so the imageloader will not cache that specific url (This brings up the issue the 302 redirect url will be cached, but should be handled on the setShouldCache(false) call for the request)
OR
I want to be able to invalidate or remove caching from the specified URL using Google Volley and it's imageloader.
I am using the singleton class provided from the android developers guide including the default image loading request:
RequestEntity.getInstance(mContext).getImageLoader().get(mImageURL,
ImageLoader.getImageListener(mImageView,
R.drawable.default_avatar, R.drawable.default_avatar));
The imageloader provided from android volley uses a cachekey in order to cache requests, but during its process it makes a simple image request.
So just use a request:
Request<Bitmap> imageRequest = new ImageRequest(requestUrl, listener,
maxWidth, maxHeight, scaleType, Bitmap.Config.RGB_565, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
imageView.setImageResource(R.drawable.default_avatar);
}
});
imageRequest.setShouldCache(false);
RequestEntity.getInstance(this).getRequestQueue().add(req);
I have an project where I want to load some url came from webservice into a webView but. for that I am facing the following problem. Please help.
url = "www.facebook.com"
wv.loadUrl(url);
for above code I got an error say unable load webpage.
But if i changed this to
url = "https://www.facebook.com"
its working but I need to load url without having http or https mentioned .
Please help me on this.
add this by your own code like
String urlCameFromServer = "www.facebook.com";
if(!urlCameFromServer.contains("http")) {
urlCameFromServer = "http://"+urlCameFromServer;
}
wv.loadUrl(urlCameFromServer);
After making a second network request using Volley, I always get this error. It doesn't seem to matter what the url I put in is. Volley always claims it is malformed.
08-04 20:16:26.885 14453-14470/com.thredup.android E/Volley﹕ [994] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:127)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:110)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:101)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
Investigating further, I put a couple logs in HurlStack. In
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders),
the request that fails is REQUEST [ ] 0x0 LOW 26."
Thus, line 101 of HurlStack : URL parsedUrl = new URL(url);
fails with an empty url (request.getUrl() is empty).
I am using OkHttpStack (extending HurlStack).
Any ideas on what could be causing this?
actually the problem is with your url not with the volley. Your Url is not a URI. There is no protocol component in it. It needs http:// or whatever other protocol you intend. If you have the http in your url make sure where it is correctly formed or not.
For example your url formation should be like this
public String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
Don’t forget to read the URL Specification and make sure the URL you are providing is valid.
Make Sure that you have passed the URL as the second parameter in JsonObjectRequest or StringRequest. I made the same mistake which produced the same error like what you faced.
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Method.POST, URL, null, ResponseListener, ErrorListener);
Use
http://
OR
https://
prefix to your URL
example:
example.com/information.json
write it as
http://example.com/information.json
this Exception occur while you are hitting an Url that is not prefixed withhttp// or https//.so check there is therehttp// is with your URL.
you can get more information here and see these links