Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Java API 21到Azure MongoDB_Java_Android_Mongodb_Azure - Fatal编程技术网

Android Java API 21到Azure MongoDB

Android Java API 21到Azure MongoDB,java,android,mongodb,azure,Java,Android,Mongodb,Azure,我试图在位于Azure的MongoDB上放置一个文档。我面临的问题是无法连接到该服务。Azure提供了连接器字符串,因此它应该可以工作 我得到了这个错误 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

我试图在位于Azure的MongoDB上放置一个文档。我面临的问题是无法连接到该服务。Azure提供了连接器字符串,因此它应该可以工作

我得到了这个错误

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"

我正在使用此代码连接

//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()));
我的依赖关系

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'

    }

我尝试使用Mongo驱动程序3.2.2,但得到了不同的错误。这里的其他解决方案似乎都是相同的,并且正在发挥作用。

听起来您想使用Mongo Driver for Java从Android访问Azure上的MongoDB。有一个类似的SO线程与您的线程有相同的问题。问题的原因是官方驱动程序
mongojava驱动程序
,它在Android上不兼容。一个解决方案是使用Android的第三方驱动程序移植


然而,在Android上直接访问MongoDB并不是一个好的选择,即使是发送数据。根据我的经验,最佳做法是使用REST webservice在MongoDB上发送和存储数据,请参阅MongoDB参考以在Azure WebApps上获得由MongoDB提供的功能齐全的RESTful Web服务,或者只创建Azure移动应用程序以从Android接收数据。

这是虚拟机中的MongoDB吗?还是启用了MongoDB兼容性的DocumentDB?如果是后者:集合是否已经存在?或者你认为你的插入会隐式地创建集合?它的MongoDb在实际的Azure云上。Azure上的MongoDb只有一个选项。我也在物理电话上运行代码。我在Azure门户中手动创建了数据库和集合,该设备的用途是仅发送数据。
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'

    }