简单地说我无法连接。我已经按照文档,我似乎遇到了很多错误。
错误
05-31 15:26:24.062 15970-15970/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve static method 18243: Ljavax/management/ObjectName;.quote (Ljava/lang/String;)Ljava/lang/String;
05-31 15:26:24.062 15970-15970/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve static method 17794: Ljava/lang/management/ManagementFactory;.getRuntimeMXBean ()Ljava/lang/management/RuntimeMXBean;
05-31 15:26:24.092 15970-15970/com.example.android.slidingtabsbasic W/org.bson.ObjectId﹕ Failed to get process identifier from JMX, using random number instead
java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory
at org.bson.types.ObjectId.createProcessIdentifier(ObjectId.java:502)
at org.bson.types.ObjectId.<clinit>(ObjectId.java:460)
at com.mongodb.connection.ClusterId.<init>(ClusterId.java:47)
at com.mongodb.connection.DefaultClusterFactory.create(DefaultClusterFactory.java:40)
at com.mongodb.async.client.MongoClients.createCluster(MongoClients.java:96)
at com.mongodb.async.client.MongoClients.create(MongoClients.java:55)
at com.mongodb.async.client.MongoClients.create(MongoClients.java:75)
at com.mongodb.async.client.MongoClients.create(MongoClients.java:65)
at com.example.android.slidingtabsbasic.MainActivity.MongoDBConnection(MainActivity.java:287)
at com.example.android.slidingtabsbasic.MainActivity.onCreate(MainActivity.java:101)
at android.app.Activity.performCreate(Activity.java:5234)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
05-31 15:26:24.092 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ Cluster created with settings {hosts=[ds043082.mongolab.com:43082], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
05-31 15:26:24.102 15970-15970/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve static method 17793: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
05-31 15:26:24.102 15970-15970/com.example.android.slidingtabsbasic E/dalvikvm﹕ Could not find class 'javax.management.ObjectName', referenced from method com.mongodb.internal.management.jmx.JMXMBeanServer.registerMBean
05-31 15:26:24.102 15970-15970/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve new-instance 2774 (Ljavax/management/ObjectName;) in Lcom/mongodb/internal/management/jmx/JMXMBeanServer;
05-31 15:26:24.102 15970-15970/com.example.android.slidingtabsbasic E/dalvikvm﹕ Could not find class 'javax.management.ObjectName', referenced from method com.mongodb.internal.management.jmx.JMXMBeanServer.unregisterMBean
05-31 15:26:24.102 15970-15970/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve new-instance 2774 (Ljavax/management/ObjectName;) in Lcom/mongodb/internal/management/jmx/JMXMBeanServer;
05-31 15:26:24.112 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=ds043082.mongolab.com:43082, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/channels/AsynchronousSocketChannel;)
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve virtual method 17891: Ljava/nio/channels/AsynchronousSocketChannel;.close ()V
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve static method 17893: Ljava/nio/channels/AsynchronousSocketChannel;.open ()Ljava/nio/channels/AsynchronousSocketChannel;
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ Link of class 'Lcom/mongodb/connection/AsynchronousSocketChannelStream$BasicCompletionHandler;' failed
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic E/dalvikvm﹕ Could not find class 'com.mongodb.connection.AsynchronousSocketChannelStream$BasicCompletionHandler', referenced from method com.mongodb.connection.AsynchronousSocketChannelStream.readAsync
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ VFY: unable to resolve new-instance 1973 (Lcom/mongodb/connection/AsynchronousSocketChannelStream$BasicCompletionHandler;) in Lcom/mongodb/connection/AsynchronousSocketChannelStream;
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ Link of class 'Lcom/mongodb/connection/AsynchronousSocketChannelStream$1;' failed
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ Link of class 'Lcom/mongodb/connection/AsynchronousSocketChannelStream$1;' failed
05-31 15:26:24.112 15970-15983/com.example.android.slidingtabsbasic W/dalvikvm﹕ Link of class 'Lcom/mongodb/connection/AsynchronousSocketChannelStream$BasicCompletionHandler;' failed
05-31 15:26:24.122 15970-15983/com.example.android.slidingtabsbasic I/cluster﹕ Exception in monitor thread while connecting to server ds043082.mongolab.com:43082
com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed
at com.mongodb.connection.FutureAsyncCompletionHandler.get(FutureAsyncCompletionHandler.java:65)
at com.mongodb.connection.FutureAsyncCompletionHandler.getOpen(FutureAsyncCompletionHandler.java:43)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:60)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: java.nio.channels.AsynchronousSocketChannel
at com.mongodb.connection.AsynchronousSocketChannelStream.openAsync(AsynchronousSocketChannelStream.java:67)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:59)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
05-31 15:26:54.114 15970-15984/com.example.android.slidingtabsbasic I/System.out﹕ Operation Finished!
05-31 15:26:54.134 15970-15984/com.example.android.slidingtabsbasic I/System.out﹕ listDatabaseNames() errored: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=ds043082.mongolab.com:43082, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed}, caused by {java.lang.NoClassDefFoundError: java.nio.channels.AsynchronousSocketChannel}}]
05-31 15:26:54.194 15970-16200/com.example.android.slidingtabsbasic D/libc﹕ [net] no pids to match num= 99
05-31 15:26:54.314 15970-15970/com.example.android.slidingtabsbasic I/MainActivity﹕ Ready
05-31 15:26:54.404 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ Cluster created with settings {hosts=[ds043082.mongolab.com:43082], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
05-31 15:26:54.404 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=ds043082.mongolab.com:43082, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
05-31 15:26:54.404 15970-16215/com.example.android.slidingtabsbasic I/cluster﹕ Exception in monitor thread while connecting to server ds043082.mongolab.com:43082
com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed
at com.mongodb.connection.FutureAsyncCompletionHandler.get(FutureAsyncCompletionHandler.java:65)
at com.mongodb.connection.FutureAsyncCompletionHandler.getOpen(FutureAsyncCompletionHandler.java:43)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:60)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: java.nio.channels.AsynchronousSocketChannel
at com.mongodb.connection.AsynchronousSocketChannelStream.openAsync(AsynchronousSocketChannelStream.java:67)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:59)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
05-31 15:26:54.414 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ Cluster created with settings {hosts=[ds043082.mongolab.com:43082], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
05-31 15:26:54.424 15970-15970/com.example.android.slidingtabsbasic I/cluster﹕ No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=ds043082.mongolab.com:43082, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
05-31 15:26:54.434 15970-16217/com.example.android.slidingtabsbasic I/cluster﹕ Exception in monitor thread while connecting to server ds043082.mongolab.com:43082
com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed
at com.mongodb.connection.FutureAsyncCompletionHandler.get(FutureAsyncCompletionHandler.java:65)
at com.mongodb.connection.FutureAsyncCompletionHandler.getOpen(FutureAsyncCompletionHandler.java:43)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:60)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: java.nio.channels.AsynchronousSocketChannel
at com.mongodb.connection.AsynchronousSocketChannelStream.openAsync(AsynchronousSocketChannelStream.java:67)
at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:59)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:856)
05-31 15:26:54.454 15970-15970/com.example.android.slidingtabsbasic I/Adreno200-EGL﹕ <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build: (CL2858274)
Build Date: 12/24/12 Mon
Local Branch: D1L_VWZ1211_RB4_AU37-1738J
Remote Branch:
Local Patches:
Reconstruct Branch:
这是我正在执行以尝试建立连接的代码。我对天气感到困惑我是否真的需要提供连接字符串的登录信息?我已经尝试了两种方法,但它们都会导致错误,但我想知道何时使用我的凭据,何时不会?
public void MongoDBConnection() throws InterruptedException{
//Makes Connection to Database
mongoClient = MongoClients.create("mongodb://xxx:xxx**X@theConnection/database");
final CountDownLatch latch = new CountDownLatch(1);
SingleResultCallback<Void> callbackWhenFinished = new SingleResultCallback<Void>() {
@Override
public void onResult(final Void result, final Throwable t) {
System.out.println("Operation Finished!");
if (t != null) {
System.out.println("listDatabaseNames() errored: " + t.getMessage());
}
latch.countDown();
}
};
mongoClient.listDatabaseNames().forEach(new Block<String>() {
@Override
public void apply(final String s) {
System.out.println(s);
}
}, callbackWhenFinished);
latch.await();
db = mongoClient.getDatabase("le_users");
//Gets Table
UserDataCollection = db.getCollection("UserData");
}
Manfiest Permissions
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
像这样在OnCreate中调用
try {
MongoDBConnection();
} catch(Exception e) {
e.printStackTrace();
}
答案 0 :(得分:0)
异步Java驱动程序依赖于Java 7中引入的AsynchronousSocketChannel类,并且从堆栈跟踪看来该类不可用,至少不在您正在测试的Android版本中。< / p>
异步驱动程序也可以与Netty一起使用,作为AsynchronousSocketChannel的替代方法,因此您可以尝试一下。在3.0驱动程序中,它需要将“org.mongodb.async.type”系统属性设置为“netty”,但在3.1中,还有一种方法可以以编程方式执行此操作。