我正在寫一個Android應用程序,需要訪問存儲在mongodb數據庫中的數據。在我的創建方法中,我一直在獲取「UnknownHostException」錯誤。我已經將Internet權限添加到清單文件中,重新啓動了我的開發機器,並應用了try/catch。現在,當我運行應用程序時,應用程序崩潰(正如應用程序打開時一樣)。當我使用我爲Android之外的數據庫(CrumbsDb)編寫的類時,它按預期工作。請幫忙。對不起,如果我的問題不夠詳細,我是堆棧溢出和compsci的新手。Android:我的應用程序不會運行,因爲我需要處理一個unknownhostexception。當我這樣做崩潰
String name = "Crumb Not Available";
try {
CrumbsDb db = new CrumbsDb();
name = db.getName("Chipotle");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextView crumbName = (TextView) findViewById(R.id.crumb_name);
crumbName.setText(name);
以下是錯誤日誌
01-10 13:42:37.223: I/dalvikvm(506): Could not find method java.lang.management.ManagementFactory.getRuntimeMXBean, referenced from method org.bson.types.ObjectId.<clinit>
01-10 13:42:37.223: W/dalvikvm(506): VFY: unable to resolve static method 1544: Ljava/lang/management/ManagementFactory;.getRuntimeMXBean()Ljava/lang/management/RuntimeMXBean;
01-10 13:42:37.273: D/dalvikvm(506): VFY: replacing opcode 0x71 at 0x0071
01-10 13:42:37.273: D/dalvikvm(506): VFY: dead code 0x0074-007c in Lorg/bson/types/ObjectId;.<clinit>()V
01-10 13:42:37.373: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.373: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.373: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.373: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.373: W/dalvikvm(506): VFY: unable to find class referenced in signature (Lcom/mongodb/DBPortPool;)
01-10 13:42:37.373: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.383: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.383: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.383: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.383: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.383: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.383: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.383: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.393: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.393: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.393: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.393: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.393: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.403: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.403: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.403: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.403: I/dalvikvm(506): Could not find method com.mongodb.DBPortPool.getServerAddress, referenced from method com.mongodb.DBTCPConnector._set
01-10 13:42:37.403: W/dalvikvm(506): VFY: unable to resolve virtual method 441: Lcom/mongodb/DBPortPool;.getServerAddress()Lcom/mongodb/ServerAddress;
01-10 13:42:37.403: D/dalvikvm(506): VFY: replacing opcode 0x6e at 0x002b
01-10 13:42:37.403: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.403: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.403: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.413: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.413: D/dalvikvm(506): VFY: dead code 0x002e-0043 in Lcom/mongodb/DBTCPConnector;._set (Lcom/mongodb/ServerAddress;)Z
01-10 13:42:37.413: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.413: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.413: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.413: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.423: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.423: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.423: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.423: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.423: W/dalvikvm(506): VFY: unable to find class referenced in signature (Lcom/mongodb/DBPortPool;)
01-10 13:42:37.443: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.443: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.443: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.443: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.454: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.454: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.454: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.454: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.454: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.454: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.454: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.454: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.463: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.463: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.473: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.473: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.473: I/dalvikvm(506): Could not find method com.mongodb.DBPortPool.get, referenced from method com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize
01-10 13:42:37.473: W/dalvikvm(506): VFY: unable to resolve virtual method 438: Lcom/mongodb/DBPortPool;.get()Lcom/mongodb/DBPort;
01-10 13:42:37.473: D/dalvikvm(506): VFY: replacing opcode 0x6e at 0x0008
01-10 13:42:37.473: D/dalvikvm(506): VFY: dead code 0x000b-0076 in Lcom/mongodb/DBTCPConnector;.fetchMaxBsonObjectSize()I
01-10 13:42:37.473: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.473: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.473: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.483: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.483: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.483: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.483: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.483: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.493: I/dalvikvm(506): Could not find method com.mongodb.DBPortPool.getServerAddress, referenced from method com.mongodb.DBTCPConnector.getAddress
01-10 13:42:37.493: W/dalvikvm(506): VFY: unable to resolve virtual method 441: Lcom/mongodb/DBPortPool;.getServerAddress()Lcom/mongodb/ServerAddress;
01-10 13:42:37.493: D/dalvikvm(506): VFY: replacing opcode 0x6e at 0x0004
01-10 13:42:37.493: D/dalvikvm(506): VFY: dead code 0x0007-0007 in Lcom/mongodb/DBTCPConnector;.getAddress()Lcom/mongodb/ServerAddress;
01-10 13:42:37.493: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.493: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.493: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.503: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.503: W/dalvikvm(506): VFY: unable to find class referenced in signature (Lcom/mongodb/DBPortPool;)
01-10 13:42:37.503: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.503: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.503: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.503: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.503: W/dalvikvm(506): VFY: unable to find class referenced in signature (Lcom/mongodb/DBPortPool;)
01-10 13:42:37.513: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.513: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.513: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.513: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.513: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.513: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.523: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.523: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.523: I/dalvikvm(506): Could not find method com.mongodb.DBPortPool.get, referenced from method com.mongodb.DBTCPConnector.testMaster
01-10 13:42:37.523: W/dalvikvm(506): VFY: unable to resolve virtual method 438: Lcom/mongodb/DBPortPool;.get()Lcom/mongodb/DBPort;
01-10 13:42:37.523: D/dalvikvm(506): VFY: replacing opcode 0x6e at 0x0003
01-10 13:42:37.523: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.523: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.523: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.523: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.533: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.533: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.533: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.533: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.533: I/dalvikvm(506): Could not find method com.mongodb.DBPortPool.done, referenced from method com.mongodb.DBTCPConnector.testMaster
01-10 13:42:37.533: W/dalvikvm(506): VFY: unable to resolve virtual method 437: Lcom/mongodb/DBPortPool;.done (Ljava/lang/Object;)V
01-10 13:42:37.533: D/dalvikvm(506): VFY: replacing opcode 0x6e at 0x0032
01-10 13:42:37.533: D/dalvikvm(506): VFY: dead code 0x0006-0023 in Lcom/mongodb/DBTCPConnector;.testMaster()V
01-10 13:42:37.533: D/dalvikvm(506): VFY: dead code 0x0035-0035 in Lcom/mongodb/DBTCPConnector;.testMaster()V
01-10 13:42:37.543: I/dalvikvm(506): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method com.mongodb.DBPortPool$Holder.<init>
01-10 13:42:37.543: W/dalvikvm(506): VFY: unable to resolve static method 1543: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer()Ljavax/management/MBeanServer;
01-10 13:42:37.543: D/dalvikvm(506): VFY: replacing opcode 0x71 at 0x0011
01-10 13:42:37.543: D/dalvikvm(506): VFY: dead code 0x0014-0014 in Lcom/mongodb/DBPortPool$Holder;.<init> (Lcom/mongodb/MongoOptions;)V
01-10 13:42:37.553: E/dalvikvm(506): Could not find class 'javax.management.ObjectName', referenced from method com.mongodb.DBPortPool$Holder.createObjectName
01-10 13:42:37.553: W/dalvikvm(506): VFY: unable to resolve new-instance 305 (Ljavax/management/ObjectName;) in Lcom/mongodb/DBPortPool$Holder;
01-10 13:42:37.553: D/dalvikvm(506): VFY: replacing opcode 0x22 at 0x004e
01-10 13:42:37.553: D/dalvikvm(506): VFY: dead code 0x0050-0053 in Lcom/mongodb/DBPortPool$Holder;.createObjectName (Lcom/mongodb/ServerAddress;)Ljavax/management/ObjectName;
01-10 13:42:37.553: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.553: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.553: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.553: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.553: E/dalvikvm(506): Could not find class 'com.mongodb.DBPortPool', referenced from method com.mongodb.DBPortPool$Holder.close
01-10 13:42:37.553: W/dalvikvm(506): VFY: unable to resolve check-cast 56 (Lcom/mongodb/DBPortPool;) in Lcom/mongodb/DBPortPool$Holder;
01-10 13:42:37.553: D/dalvikvm(506): VFY: replacing opcode 0x1f at 0x0017
01-10 13:42:37.563: D/dalvikvm(506): VFY: dead code 0x0019-003a in Lcom/mongodb/DBPortPool$Holder;.close()V
01-10 13:42:37.563: I/dalvikvm(506): Failed resolving Lcom/mongodb/util/SimplePool; interface 298 'Ljavax/management/DynamicMBean;'
01-10 13:42:37.563: W/dalvikvm(506): Link of class 'Lcom/mongodb/util/SimplePool;' failed
01-10 13:42:37.563: W/dalvikvm(506): Unable to resolve superclass of Lcom/mongodb/DBPortPool; (146)
01-10 13:42:37.563: W/dalvikvm(506): Link of class 'Lcom/mongodb/DBPortPool;' failed
01-10 13:42:37.563: E/dalvikvm(506): Could not find class 'com.mongodb.DBPortPool', referenced from method com.mongodb.DBPortPool$Holder.get
01-10 13:42:37.563: W/dalvikvm(506): VFY: unable to resolve check-cast 56 (Lcom/mongodb/DBPortPool;) in Lcom/mongodb/DBPortPool$Holder;
01-10 13:42:37.573: D/dalvikvm(506): VFY: replacing opcode 0x1f at 0x0006
01-10 13:42:37.573: D/dalvikvm(506): VFY: dead code 0x0008-0099 in Lcom/mongodb/DBPortPool$Holder;.get (Lcom/mongodb/ServerAddress;)Lcom/mongodb/DBPortPool;
01-10 13:42:37.573: D/AndroidRuntime(506): Shutting down VM
01-10 13:42:37.573: W/dalvikvm(506): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-10 13:42:37.593: E/AndroidRuntime(506): FATAL EXCEPTION: main
01-10 13:42:37.593: E/AndroidRuntime(506): java.lang.NoClassDefFoundError: com.mongodb.DBPortPool
01-10 13:42:37.593: E/AndroidRuntime(506): at com.mongodb.DBPortPool$Holder.get(DBPortPool.java:57)
01-10 13:42:37.593: E/AndroidRuntime(506): at com.mongodb.DBTCPConnector._set(DBTCPConnector.java:488)
01-10 13:42:37.593: E/AndroidRuntime(506): at com.mongodb.DBTCPConnector.<init>(DBTCPConnector.java:44)
01-10 13:42:37.593: E/AndroidRuntime(506): at com.mongodb.Mongo.<init>(Mongo.java:272)
01-10 13:42:37.593: E/AndroidRuntime(506): at breadcrumbs.java.CrumbsDb.<init>(CrumbsDb.java:21)
01-10 13:42:37.593: E/AndroidRuntime(506): at breadcrumbs.java.BreadCrumbsActivity.onCreate(BreadCrumbsActivity.java:28)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.os.Looper.loop(Looper.java:123)
01-10 13:42:37.593: E/AndroidRuntime(506): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-10 13:42:37.593: E/AndroidRuntime(506): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 13:42:37.593: E/AndroidRuntime(506): at java.lang.reflect.Method.invoke(Method.java:507)
01-10 13:42:37.593: E/AndroidRuntime(506): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-10 13:42:37.593: E/AndroidRuntime(506): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-10 13:42:37.593: E/AndroidRuntime(506): at dalvik.system.NativeStart.main(Native Method)
我不確定你可以在Android應用程序中使用mongoDB數據庫,你得到的棧跟蹤是什麼? – 2012-01-10 18:32:11
你確定你在應用程序mongoDB系統的主機名/ IP是否正確?你是否從你的開發機器ping mongoDB機器? – kosa 2012-01-10 18:47:32
是的,我確定。我在文本編輯中使用純java文件測試了主機名/ ip,並運行它來打印出結果;它按照預期工作。儘管我現在剛剛發現並收到了100%的數據包丟失(主機是32位Amazon EC2 Linux機箱)。 – 2012-01-10 19:38:52