Android Volley MalformedURLException Bad URL
Asked Answered
H

4

22

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?

Hillari answered 5/8, 2014 at 3:30 Comment(12)
I get this error too, can you explain how you solved this? thanks.Cutis
I m getting this error too, please share the solution in case u have solved it, thanx a lot!Jovia
@Nightly Have you found any solution for this ?Rustler
@RevanthRev: I think you should post your code for more informationShaft
https://mcmap.net/q/588795/-malformed-url-exception-while-using-volley/4522954 @ShaftRustler
@RevanthRev: your issue has been fixed?Shaft
yes BNK thanks for comingRustler
Can you add the code where you make your request?Vargueno
Toast the url string. is it blank??. if so, is not really a Volley issue if the url is blankBrazilin
Add your code snippet too. How you implemented it? Code inside onResponse & errorlistener is not required.Boothman
Is this exception coming in your second request using volley and not in first. If this is the case then this was a bug in volley. Not sure if it fixed now or not.Congruity
Hi @Eric , Will you accept my answer. So that it wont listead in unanswered questions and helpful for othersStandardize
S
19

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.

Standardize answered 3/9, 2015 at 7:18 Comment(0)
R
4

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);
Rustler answered 2/9, 2015 at 8:52 Comment(1)
Here i can use JsonArrayRequest I can also face same problemSubjectivism
D
3

Use http:// OR https://

prefix to your URL example: example.com/information.json write it as http://example.com/information.json

Deidredeific answered 30/11, 2015 at 8:2 Comment(0)
D
2

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

Dharna answered 3/9, 2015 at 5:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.