2

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. Have you got any solution ? Is it possible to connect both of this?

LOG:

07-11 12:40:17.655: E/AndroidRuntime(724): FATAL EXCEPTION: main
07-11 12:40:17.655: E/AndroidRuntime(724): java.lang.IllegalStateException: Could not execute method of the activity
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.view.View$1.onClick(View.java:3591)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.view.View.performClick(View.java:4084)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.view.View$PerformClick.run(View.java:16966)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.os.Handler.handleCallback(Handler.java:615)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.os.Looper.loop(Looper.java:137)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.app.ActivityThread.main(ActivityThread.java:4745)
07-11 12:40:17.655: E/AndroidRuntime(724):  at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:40:17.655: E/AndroidRuntime(724):  at java.lang.reflect.Method.invoke(Method.java:511)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-11 12:40:17.655: E/AndroidRuntime(724):  at dalvik.system.NativeStart.main(Native Method)
07-11 12:40:17.655: E/AndroidRuntime(724): Caused by: java.lang.reflect.InvocationTargetException
07-11 12:40:17.655: E/AndroidRuntime(724):  at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:40:17.655: E/AndroidRuntime(724):  at java.lang.reflect.Method.invoke(Method.java:511)
07-11 12:40:17.655: E/AndroidRuntime(724):  at android.view.View$1.onClick(View.java:3586)
07-11 12:40:17.655: E/AndroidRuntime(724):  ... 11 more
07-11 12:40:17.655: E/AndroidRuntime(724): Caused by: java.lang.NoClassDefFoundError: com.mongodb.DBPortPool
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.DBPortPool$Holder.get(DBPortPool.java:58)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.DBTCPConnector.setMasterAddress(DBTCPConnector.java:486)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.DBTCPConnector.<init>(DBTCPConnector.java:46)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.Mongo.<init>(Mongo.java:192)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.Mongo.<init>(Mongo.java:176)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.mongodb.Mongo.<init>(Mongo.java:130)
07-11 12:40:17.655: E/AndroidRuntime(724):  at com.example.easyrest.MainActivity.clickAddOfferButton_offer(MainActivity.java:66)
07-11 12:40:17.655: E/AndroidRuntime(724):  ... 14 more
2
  • 1
    what type of error are you getting? can you post the error? Commented Jul 11, 2012 at 12:55
  • java.lang.NoClassDefFoundError means VM can't load class com.mongodb.DBPortPool during execution. Commented Jul 11, 2012 at 13:01

3 Answers 3

4

Android is not supported in this driver. There is an open issue in the jira.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

I actually found it somewhat difficult to find most current mongo-java jar. Three different MongoDB sites show three different current versions. But, here's where I found 2.11.3: central.maven.org/maven2/org/mongodb/mongo-java-driver/2.11.3
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.