aloisdeniel / flutter_geocoder

Flutter plugin for forward and reverse geocoding

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime exception from flutter v 1.5

harshapulikollu opened this issue · comments

Encountering a fatal runtime exception after upgrading flutter to version 1.5, resulting in crash of app.

java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(11970): 	at android.os.AsyncTask$3.done(AsyncTask.java:353)
E/AndroidRuntime(11970): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(11970): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(11970): 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(11970): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(11970): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/AndroidRuntime(11970): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/AndroidRuntime(11970): 	at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(11970): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #2
E/AndroidRuntime(11970): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/AndroidRuntime(11970): 	at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556)
E/AndroidRuntime(11970): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:129)
E/AndroidRuntime(11970): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:215)
E/AndroidRuntime(11970): 	at com.aloisdeniel.geocoder.GeocoderPlugin$2.doInBackground(GeocoderPlugin.java:113)
E/AndroidRuntime(11970): 	at com.aloisdeniel.geocoder.GeocoderPlugin$2.doInBackground(GeocoderPlugin.java:106)
E/AndroidRuntime(11970): 	at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(11970): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(11970): 	... 4 more

See jason-simmons/flutter_plugins@70b9bfc on how to fix this

Basically you now have to do runOnUiThread(Runnable { result.success(myResult) })

Will look into it. Thankyou.

(It might be something the plugin maintainer has to do. Or you could open a pull request fixing it.)

Found this issue when working on a completely different Flutter project. In case somebody else needs a fix: for me it was enough to modify my AsyncTask slightly by moving the code that was causing the exception to the onPostExecute method:

@Override
protected void onPostExecute(HashMap result) {
  //code that was causing the exception, in my case: 
  channel.invokeMethod(...);
}

Still facing the issue. Here's the [issue]
(fluttercommunity/flutter_google_places#69 (comment))
flutter version 1.6.3
Using Geocode plugin based on a stackOverflow answer.