问题描述
我想连接到我的MongoDB(托管在)。我碰到下面的错误,当我想连接到数据库中(与Java驱动程序)
I'd like to connect to my MongoDB (hosted on MongoHQ). I get the following error when I want connect to the database (with the Java driver)
ERROR/AndroidRuntime(597): java.lang.NoClassDefFoundError: com.mongodb.DBPortPool
ERROR/AndroidRuntime(597): at com.mongodb.DBPortPool$Holder.get(DBPortPool.java:52)
ERROR/AndroidRuntime(597): at com.mongodb.DBTCPConnector._set(DBTCPConnector.java:380)
ERROR/AndroidRuntime(597): at com.mongodb.DBTCPConnector.<init>(DBTCPConnector.java:46)
ERROR/AndroidRuntime(597): at com.mongodb.Mongo.<init>(Mongo.java:138)
ERROR/AndroidRuntime(597): at com.mongodb.Mongo.<init>(Mongo.java:124)
ERROR/AndroidRuntime(597): at com.mongodb.Mongo.<init>(Mongo.java:114)
ERROR/AndroidRuntime(597): at xxx.MainActivity$1.onClick(MainActivity.java:29)
我用下面的code:
I use the following code:
Mongo mng = new Mongo("flame.mongohq.com", 27073); // <- error
DB mngDb = mng.getDB("xxx");
mngDb.authenticate("xxx", "xxx".toCharArray());
DBCollection mngColl = mngDb.getCollection("xxx");
// mText.setText("Data Count: "+Long.toString(mngColl.getCount()));
我通过属性> Java构建路径>库>添加Externel JAR
I added the driver in Eclipse via Properties>Java Build Path>Libraries>Add Externel JAR
推荐答案
该DBPortPool对JMX一个依赖关系JMX但不支持在Android上。
The DBPortPool has a dependancy on JMX however JMX is not supported on android.
出于兴趣,你有什么用呢?正如你会希望避免从手机传递数据库的用户名/密码没有安全基础设施。
Out of interest, what is your use case? As you will want to avoid passing database username/pwd from your phone without security infrastructure.
这篇关于Android版/ MongoDB的:&QUOT; NoClassDefFoundError的:com.mongodb.DBPortPool&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!