I\'ve generated Android project in Eclipse and everything work. I\'ve added a few buttons etc with events. Now, I\'m trying to create Mongo object but it throws an error. Ha
I agree with Phil it does work, but it seems to break on and off again, if you need to find more up to date libraries check out the following
For those that want the latest pre-compiled JAR files Snapshots of latest Java Drivers
If you want the source then check out GIT Source Repository and links to latest stable etc
Android is not supported in this driver. There is an open issue in the jira.
I know this is an old post, but I just wanted to share my Android + MongoDB Driver experience.
First things first, IT WORKS!
As it turns out, the issue mentioned by parvin has been fixed and closed.
However, when you use the recent version (2.11.3 as of writing), you will see that a very scary error is presenting it self, but don't worry - the driver works anyway. At least I was able to authenticate, and insert data.
The error you will see looks like this:
I/dalvikvm(17945): Could not find method java.lang.management.ManagementFactory.getRuntimeMXBean, referenced from method org.bson.types.ObjectId.<clinit>
W/dalvikvm(17945): VFY: unable to resolve static method 7096: Ljava/lang/management/ManagementFactory;.getRuntimeMXBean ()Ljava/lang/management/RuntimeMXBean;
D/dalvikvm(17945): VFY: replacing opcode 0x71 at 0x0071
I/dalvikvm(17945): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method com.mongodb.util.management.jmx.JMXMBeanServer.<init>
W/dalvikvm(17945): VFY: unable to resolve static method 7095: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
D/dalvikvm(17945): VFY: replacing opcode 0x71 at 0x0003
E/dalvikvm(17945): Could not find class 'javax.management.ObjectName', referenced from method com.mongodb.util.management.jmx.JMXMBeanServer.createObjectName
... etc. more scary stuff ...
And my working code looks like this:
MongoClient mongo = new MongoClient(ip, port);
DB db = mongo.getDB("myDatabase");
boolean auth = db.authenticate(username, password);
if (auth)
{
DBCollection collection = db.getCollection("myCollection");
DBObject jsonData = (DBObject) JSON.parse(jsonString);
collection.insert(jsonData);
}
I hope this helps someone as I was very confused about the error.