Am trying to put a document on my MongoDB located in Azure. The problem I am facing is that I can't connect to the service. Azure provides the connector string so it should be working.
I am getting this errors
03-29 15:47:24.265 3578-3578/name.bagi.levente.pedometer W/org.bson.ObjectId: Failed to get process identifier from JMX, using random number instead
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory"
and
FATAL EXCEPTION: main Process: name.bagi.levente.pedometer, PID: 3578 java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.CodeSource java.security.ProtectionDomain.getCodeSource()' on a null object reference
I am using this code to connect
//Line below causes exception
MongoClient mongoClient = new MongoClient(new MongoClientURI("AzureProvidedString?ssl=true&sslInvalidHostNameAllowed=true"));
BasicDBObject document = new BasicDBObject();
document.put("id",2);
document.put("location", 3);
document.put("steps", 4);
mongoClient.getDatabase("FitnessData").getCollection("FitnessCollection").insertOne(Document.parse(document.toJson()));
My dependencies
dependencies{
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
// https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.4.2'
}
I tried using Mongo driver 3.2.2 and am getting a different error. Other solutions here seem to be the same and are working.