Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
963 views
in Technique[技术] by (71.8m points)

android - E/Volley: [2458] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL

I'm trying to connect to database server via android.

My question is can I somehow use localhost url like this:

private const val ROOT_URL = "http://localhost/android/v1/"

Instead of providing my computer's IP address? This is my school project and I have some concerns when I present it something will not work because of the different IP.

I've already tested it like this:

private const val ROOT_URL = "http://IP/android/v1/"

And everything works. So my only question is can I replace the IP address with something static that doesn't need to be changed when I connect to another Wi-Fi network

There is errorlog when I use 'http://localhost/android/v1/' or 'https://localhost/android/v1/':

E/Volley: [2503] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL localhost/android/v1/userLogin.php
java.lang.RuntimeException: Bad URL localhost/android/v1/userLogin.php
    at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:175)
    at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
    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: localhost/android/v1/userLogin.php
    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:87)
    at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
    at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)?
    at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)?
    at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)?
question from:https://stackoverflow.com/questions/65931405/e-volley-2458-networkdispatcher-processrequest-unhandled-exception-java-lang

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...