Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Manually inputting a URL without a study ID causes a crash #301

Open
TylerADavis opened this issue Sep 8, 2022 · 0 comments
Open

Manually inputting a URL without a study ID causes a crash #301

TylerADavis opened this issue Sep 8, 2022 · 0 comments

Comments

@TylerADavis
Copy link

TylerADavis commented Sep 8, 2022

If you input a URL manually that lacks a study ID, the app will crash when it tries to deliver the toast describing the missing information in the URL. My understanding is that this crash is happening because a background thread is trying to directly trigger a toast, which should only be done by a UI thread.

Android 11 device
Procedure:

  1. Install AWARE app, with no AWARE install preexisting
  2. Approve permissions
  3. Scroll to “AWARE study” section
  4. Enter URL "https://my_website.com:8080" , press “OK”
  5. Toggle “Active” checkbox
  6. Observe crashes

Relevant line:

Toast.makeText(Aware_Join_Study.this, "Missing API key or study ID. Scanned: " + study_url, Toast.LENGTH_SHORT).show();

2022-09-08 13:08:59.360 11549-11572/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    Process: com.aware.phone, PID: 11549
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$4.done(AsyncTask.java:415)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare()
        at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:157)
        at android.widget.Toast.getLooper(Toast.java:179)
        at android.widget.Toast.<init>(Toast.java:164)
        at android.widget.Toast.makeText(Toast.java:497)
        at android.widget.Toast.makeText(Toast.java:480)
        at com.aware.phone.ui.Aware_Join_Study$PopulateStudy.doInBackground(Aware_Join_Study.java:385)
        at com.aware.phone.ui.Aware_Join_Study$PopulateStudy.doInBackground(Aware_Join_Study.java:278)
        at android.os.AsyncTask$3.call(AsyncTask.java:394)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 

For possible fixes, see https://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant