0

I've got 2 different devices in which I'm testing my App. One of them has Android 4.0.3 and the other one 4.3.

Normally, I don't care which one I'm using but as I need to upload files to dropbox and download them in other device, I started to use both. The thing is, with the one with Jelly Bean, the code works perfectly and the file is uploaded. It doesn't happen the same with the one with IceCream: fileObserver throws a, theoretically, unhandled exception and i say theoretically because the statement where it crashes is inside a try-catch block.

Well, the code where the app gets crashed in this Icecream device is the following:

                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());
                }

It crashes just on the call:

UploadFileToDropbox upload = new UploadFileToDropbox(MainActivity.mDBApi,
                                file, Constants.DROPBOX_DIR + "/" + fileName);

When debugging, it doesn't even get inside the constructor of UploadFileToDropbox. This is class by the way is implemented in an AsynTask and the fileObserver exists in a Service running in the main thread.

Any idea of what the problem is?

Thanks in advance

UPDATE

Stack Trace:

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
Fernando
  • 751
  • 2
  • 13
  • 27
  • 1
    A question of this type should include the crash log. – Chris Stratton Nov 01 '14 at 19:09
  • sorry, english it's not my mother tongue. you mean adding another tag next to android, throwable and fileobserver? – Fernando Nov 01 '14 at 19:18
  • I believe that he means adding the Java stack trace showing your exception, pulled from LogCat, to your question: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Nov 01 '14 at 19:44
  • there you are, I've updated my question :) – Fernando Nov 01 '14 at 20:12
  • 1
    You are trying to create an AsyncTask from your file observer thread, but AsyncTasks can only be created from the UI thread. Since you are already off the UI thread you may not need one - or you can use a different threading mechanism. – Chris Stratton Nov 01 '14 at 21:41
  • I'm gonna try it, but still don't get why it works in one of the devices and not in the other one :( – Fernando Nov 01 '14 at 23:12

0 Answers0