简体   繁体   English

java.net.UnknownHostException:无法解析主机“@MYIPADDRESS,当使用android + mongodb时

[英]java.net.UnknownHostException: Unable to resolve host "@MYIPADDRESS, when using android + mongodb

I have created a MongoClientURI like this: 我创建了一个像这样的MongoClientURI:

MongoClientURI uri = new MongoClientURI( "mongodb://User_name:Password@MyIPAddress:27017/"+TEST_SKETCH_APP );

        MongoClient instance = MongoDatabaseConnection.getInstance(uri);
        DB db = instance.getDB(uri.getDatabase());
        DBCollection collection = db.getCollection(SKETCH_COLLECTION);

        BasicDBObject  dbObject = new BasicDBObject();

        dbObject.put("name", url[0]);
        dbObject.put("password", url[1]);
        dbObject.put("email", url[2]);
        dbObject.put("phoneNumber", url[3]);

        collection.insert(dbObject);

And I am calling this method from AsyncTask : 我从AsyncTask调用这个方法:

@Override
    protected JSONObject doInBackground(String... urls) {

        // params comes from the execute() call: params[0] is the url.
        try {
            return saveValues(urls);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return  null;
    }

I also have all permissions required for internet connection too: 我也拥有互联网连接所需的所有权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

But still I am not able to insert values to the database running in that IP address. 但是我仍然无法向在该IP地址中运行的数据库插入值。 The full error says : 完整错误说:

Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}.
Client view of cluster state is {type=Unknown, servers=[{address=@MYIPADDRESS:27017,
 type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: 
 Exception opening the socket}, caused by {java.net.UnknownHostException: 
 Unable to resolve host "@MYIPADDRESS": No address associated with hostname}, 
 caused by {android.system.GaiException: android_getaddrinfo failed: 
 EAI_NODATA (No address associated with hostname)}}]

I know the IP ADDRESS is correct as I can type this in chrome http://MYIPADDRESS:27017/ 我知道IP ADDRESS是正确的,因为我可以在chrome http://MYIPADDRESS:27017/

And got this in return: 得到这个回报:

It looks like you are trying to access MongoDB over HTTP on the native driver port.

FWIW I was getting the same error. FWIW我得到了同样的错误。 I was trying to connect statically, but you need to do it in the constructor. 我试图静态连接,但你需要在构造函数中进行连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.net.UnknownHostException:无法解析主机没有与主机名关联的地址 - java.net.UnknownHostException: Unable to resolve host No address associated with hostname Android 6.0:java.net.UnknownHostException:无法解析主机。 在Android 7.0上正常工作 - Android 6.0 : java.net.UnknownHostException: Unable to resolve host. Working fine in Android 7.0 Android API 23 java.net.UnknownHostException:无法解析主机“URL”:没有与主机名关联的地址 - Android API 23 java.net.UnknownHostException: Unable to resolve host “URL”: No address associated with hostname 重新启动java.net时android应用程序崩溃。UnknownHostException:无法解析主机 - android app crashes on reboot java.net.UnknownHostException: Unable to resolve host Android改装-HTTP失败:java.net.UnknownHostException:无法解析主机{我的基本url}:没有与主机名关联的地址 - Android Retrofit - HTTP FAILED: java.net.UnknownHostException: Unable to resolve host {my base url}: No address associated with hostname java.net.UnknownHostException:无法解析主机“www.google.com” - java.net.UnknownHostException: Unable to resolve host “www.google.com” 错误:java.net.UnknownHostException:无法解析主机“api.themoviedb.org” - Error: java.net.UnknownHostException: Unable to resolve host "api.themoviedb.org java.net.UnknownHostException:无法解析主机“<url> &quot;: 没有与主机名和字符 0 处的输入结束关联的地址 - java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname and End of input at character 0 of java.net.UnknownHostException:无法解析主机“ s3-ap-northeast-1.amazonaws.com”:没有与主机名关联的地址 - java.net.UnknownHostException: Unable to resolve host “s3-ap-northeast-1.amazonaws.com”: No address associated with hostname java.net.UnknownHostException:无法解析主机“api.themoviedb.org” - java.net.UnknownHostException: Unable to resolve host "api.themoviedb.org
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM