Im using Java connect with MySQL and Json will send data to android, When I send data from Java to json by URL address:
http://192.168.1.221:9999/rentalcar_service/category/getAllManufacturer
everything's fine, but when I parse data in Android I received an error result following as:
private static final String URL_MANUFACTURERS = "http://192.168.1.221:9999/rentalcar_service/category/getAllManufacturer";
Logcat:
W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:223)
W/System.err: ... 25 more
I/MemoryCache: cache size=0 length=4
W/System.err: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 9999) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:234)
W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122)
(192.168.1.221) IP address is my PC, if I change from 192.168.1.221 to localhost, I still receive same error.
How to fix this problem? Thank so much !
In my case: I changed to another wifi connection , and solved it. Because on my browser the link was opening.
ECONNREFUSED means that the connection was attempted and the remote host port is not listening. Hence this can be caused because of:
Is it a valid IP? check using ifconfig or ipconfig. u can try pinging the server.
Details regarding the error can be understood from here: https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/libcore/io/ErrnoException.java https://developer.android.com/reference/android/system/ErrnoException.html
If you are trying to access a mock local server (i.e. localhost) it won't work, because android runs on a separate environment (a device, or emulator), i.e. it has a different localhost than your development machine... you have to publish your server somewhere online.
If you just want a JSON in a REST api, you can use My-Json-Server.