在我的Android应用程序中,当我与数据库建立连接时,我收到java.io.IOException
。请告诉我这是什么问题?
代码:
public void connect_to_db() {
try {
URL requestUrl = new URL("url for MongoDB database");
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
connection.setRequestProperty("Accept-Encoding", "identity");
connection.connect();
}
catch(Exception exp) {
Log.e("TAG","Exception",exp);
}
}
错误:
05-09 03:07:22.711 2962-2962/com.example.abc.project1 E/TAG: Exception
java.io.IOException
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:87)
at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
at com.example.abc.project1.LocationDetector.connect_to_db(LocationDetector.java:85)
at com.example.abc.project1.LocationDetector.onLocationChanged(LocationDetector.java:37)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:257)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:186)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:202)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5410)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)