我有2个不同的设备,我正在测试我的应用程序。其中一个有Android 4.0.3,另一个有4.3。
通常情况下,我不关心我使用的是哪一个,但由于我需要将文件上传到Dropbox并在其他设备中下载,我开始使用它们。问题是,与Jelly Bean一起使用,代码完美无缺,文件上传。与IceCream不同的是:fileObserver抛出一个理论上未处理的异常,理论上我说它崩溃的语句在try-catch块中。
嗯,应用程序在这个Icecream设备中崩溃的代码如下:
try {
/* Some statements and stuff to do
...................
.....................
.........................
*/
File file = new File(mEncryptedDirectoryPath + "/" + fileName);
if (CheckConnection.isConnected(getApplicationContext())) {
UploadFileToDropbox upload = new UploadFileToDropbox(MainActivity.mDBApi,
file, Constants.DROPBOX_DIR + "/" + fileName);
upload.execute();
}
else {
// other stuff
}
}
catch (Exception e){
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
Log.i("Exception", errors.toString());
}
它在电话会议中崩溃:
UploadFileToDropbox upload = new UploadFileToDropbox(MainActivity.mDBApi,
file, Constants.DROPBOX_DIR + "/" + fileName);
调试时,它甚至不会进入UploadFileToDropbox的构造函数。顺便说一句,这是在AsynTask中实现的,而fileObserver存在于主线程中运行的服务中。
知道问题是什么?
提前致谢
更新
堆栈追踪:
11-01 21:23:40.310: I/Exception(32199): java.lang.ExceptionInInitializerError
11-01 21:23:40.310: I/Exception(32199): at com.example.example.SecureSharing$1.onEvent(SecureSharing.java:136)
11-01 21:23:40.310: I/Exception(32199): at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:125)
11-01 21:23:40.310: I/Exception(32199): at android.os.FileObserver$ObserverThread.observe(Native Method)
11-01 21:23:40.310: I/Exception(32199): at android.os.FileObserver$ObserverThread.run(FileObserver.java:88)
11-01 21:23:40.310: I/Exception(32199): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
11-01 21:23:40.310: I/Exception(32199): at android.os.Handler.<init>(Handler.java:121)
11-01 21:23:40.310: I/Exception(32199): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
11-01 21:23:40.310: I/Exception(32199): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
11-01 21:23:40.310: I/Exception(32199): at android.os.AsyncTask.<clinit>(AsyncTask.java:190)
11-01 21:23:40.310: I/Exception(32199): ... 4 more