TripSit / tripmobile

TripSit mobile app for Android
GNU General Public License v3.0
12 stars 4 forks source link

Factsheets error handling doesn't work #13

Closed EddieCurtis closed 9 years ago

EddieCurtis commented 9 years ago

To reproduce, type any invalid drug name into the factsheets search. This is happening because we're not allowed to show error messages from a background thread (see http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare)

I suggest using a callback in Factsheets to use the handleGenericError(String) method it inherits from ErrorHandlingActivity

 java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:300)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)
        at android.os.Handler.<init>(Handler.java:114)
        at android.app.Dialog.<init>(Dialog.java:108)
        at android.app.AlertDialog.<init>(AlertDialog.java:125)
        at android.app.AlertDialog$Builder.create(AlertDialog.java:967)
        at android.app.AlertDialog$Builder.show(AlertDialog.java:986)
        at me.tripsit.mobile.common.ErrorHandlingActivity.handleGenericError(ErrorHandlingActivity.java:22)
        at me.tripsit.mobile.factsheets.DrugInfoAsyncTask.doInBackground(DrugInfoAsyncTask.java:38)
        at me.tripsit.mobile.factsheets.DrugInfoAsyncTask.doInBackground(DrugInfoAsyncTask.java:16)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)`
EddieCurtis commented 9 years ago

Also consider using a toast instead of an error if the response came back successfully but was for an invalid drug name. I don't think we need the user's input to acknowledge that their search was invalid.

EddieCurtis commented 9 years ago

I've mostly fixed this in da488e4211b33887985a2339cc3026bb96393207 , but the error text is black on my dialog which isn't ideal. Need to find a way around that before this is finished.

EddieCurtis commented 9 years ago

This is now fixed