Skip to content

Instantly share code, notes, and snippets.

@melix
Created May 27, 2014 17:13
Show Gist options
  • Save melix/45a62f5c9fc10ff60994 to your computer and use it in GitHub Desktop.
Save melix/45a62f5c9fc10ff60994 to your computer and use it in GitHub Desktop.
Tired of AsyncTask in Android?
// Tired of AsyncTask in Android?
// Here's how you could write it in Groovy!
Fluent.async {
new URL('http://foo').text
}.then { text ->
textView.text = text
}
@etsinko
Copy link

etsinko commented Apr 10, 2015

This particular example crashes for me with the following stacktrace:

    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:841)
     Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[]
            at me.champeau.gr8confagenda.app.Fluent.doInBackground(Fluent.groovy)
            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:841)

@ikim23
Copy link

ikim23 commented Nov 17, 2016

etsinko: I had the same problem. You need to download this class to your project and save it as Fluent.java, not Fluent.groovy. Then it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment