0

What I am doing is I create an class named MainGame with the View view in it. In another package I have another class that I run when the program starts. This class is a subclass to MainGame. When I try in this class call this view I created in MainGame and modify it, it crashes.

01-25 16:21:43.195: E/AndroidRuntime(1683): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

I know what this error message means, but what shall I do to fix it?

SlowDeepCoder
  • 864
  • 3
  • 11
  • 27

1 Answers1

1

For those who come across this later, Daniel found a solution in this post: How to access original activity's views from spawned background service

Community
  • 1
  • 1
MikeC
  • 374
  • 2
  • 9
  • First up, the view I'm talking about is an AdView, in the UI thread I try to call: if (adView != null){ a.setVisibility(View.INVISIBLE) This is because I don't want the app to show up in this class. – SlowDeepCoder Jan 25 '12 at 19:08
  • How/where does the adView get created? Is it inflated or added somewhere else? – MikeC Jan 25 '12 at 19:37
  • In the MainGame class, its created just like a normal View, I just wanna ajust it from another place. – SlowDeepCoder Jan 25 '12 at 19:49
  • Can you provide a call stack of the crash? Or dump out the results of Thread.currentThread().getStackTrace() where you call setVisibility() – MikeC Jan 25 '12 at 23:10
  • Do I need to? The only thing I wanna do is to change the view from another class via a class variable that reference to the same object. – SlowDeepCoder Jan 26 '12 at 18:57
  • It's hard to tell what the exact cause is from your post as it is. As with most issues like this, it's likely to be easier to solve by looking at the code. A better option might be to post the code for the classes, or a subset so I can try running something similar. – MikeC Jan 26 '12 at 19:01
  • http://stackoverflow.com/questions/1157814/how-to-access-original-activitys-views-from-spawned-background-service There is a solution for my problem, thank you for taking your time anyway, I accept you answer and give it a +1 – SlowDeepCoder Jan 26 '12 at 21:19
  • Thanks! Glad you were able to find an answer! – MikeC Jan 26 '12 at 21:57