gpt4 book ai didi

使用 android + mongodb 时出现 java.net.UnknownHostException : Unable to resolve host "@MYIPADDRESS,

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:27 24 4
gpt4 key购买 nike

我创建了一个像这样的 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);

我从 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;
}

我也拥有互联网连接所需的所有权限:

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

但我仍然无法将值插入到在该 IP 地址中运行的数据库中。完整的错误说:

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)}}]

我知道 IP 地址是正确的,因为我可以在 chrome 中输入此地址 http://MYIPADDRESS:27017/

并得到了返回:

您似乎正在尝试在 native 驱动程序端口上通过 HTTP 访问 MongoDB。

最佳答案

FWIW我遇到了同样的错误。我试图静态连接,但您需要在构造函数中执行此操作。

关于使用 android + mongodb 时出现 java.net.UnknownHostException : Unable to resolve host "@MYIPADDRESS,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40549919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com