Trying to connect to shared mongodb using java

this is the code i’m using to connect from my android device to Atlas mongodb cluster…
it’s two week i’m trying…no result.
Please someone can try to help me to solve this problem ?

String uri = “mongodb+srv://”+ TestApp + “:” + Password + “”;

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    MongoClient client = new MongoClient(uri,27017);

   try {
        MongoDatabase database = client.getDatabase("TestApp");
        MongoCollection<Document> collection = database.getCollection("TestAppCollection");
        BsonDocument filter = new BsonDocument();
    } catch (MongoCommandException me) {
        return "An error occurred while attempting to run a command: " + me;
    } catch (MongoClientException mcexception) {
        return "MCERR# " + mcexception.getMessage();
    } catch (Exception exception) {
        return "ERR# " + exception.getMessage();
    return "Connected";

the error i get it’s:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb+srv://, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: Unable to resolve host “mongodb+srv://”: No address associated with hostname}, caused by { Unable to resolve host “mongodb+srv://”: No address associated with hostname}}]

thanks in advance

1 Like

You can try this link. My one is solved by following the instruction in this link.