rosjava / android_apps

Applications built on top of the rosjava android libraries.
132 stars 112 forks source link

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. Please help #85

Closed WestbrookZero closed 5 years ago

WestbrookZero commented 5 years ago

In the make a map mudule,apk run crash,Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7390) at android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:3481) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:848) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:848) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:848) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:848) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:848) at android.view.View.setFlags(View.java:13273) at android.view.View.setClickable(View.java:9837) at android.view.View.setOnClickListener(View.java:6117) at com.github.rosjava.android_apps.make_a_map.ViewControlLayer.(ViewControlLayer.java:84) at com.github.rosjava.android_apps.make_a_map.MainActivity.init(MainActivity.java:300) at org.ros.android.RosActivity$1$1.doInBackground(RosActivity.java:89) at org.ros.android.RosActivity$1$1.doInBackground(RosActivity.java:86) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764) 

jubeira commented 5 years ago

Hi @WestbrookZero, could you add more info about what you were doing exactly when the exception happened?

WestbrookZero commented 5 years ago

I have solved the problem, this.act.runOnUiThread(new Runnable() { @Override public void run() { // refresh ui ViewControlLayer.this.cameraView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ swapViews(); } }); ViewControlLayer.this.mapView.setClickable(true); ViewControlLayer.this.cameraView.setClickable(false); } }); otherwise the make a map app crash when it started,in the ViewControlLayer.java this line:"this.cameraView.setOnClickListener"

jubeira commented 5 years ago

Alright, great! Please feel free to open a PR with your proposed patch if you want. Thanks in advance!

WestbrookZero commented 5 years ago

cannot display map,how to display the map in the make a map app ? image