0

I don't understand why I'm receiving a ClassCastException when I use this line:

Activity a=(Activity)photoToLoad.imageView.getContext();

That is taken from the LazyList example (the second answer) and in that project it works, but when I use the class in mine, it doesn't work. It is necessary to obtain an Activity to use the runOnUIThread method to set the downloaded Bitmap to the ImageView and avoid handlers. What am I doing wrong?

Community
  • 1
  • 1
Adrian
  • 721
  • 2
  • 11
  • 34
  • You should never, ever, do that. I don't see a single legitimate reason to cast anything to an `(Activity)` – Falmarri Feb 07 '11 at 17:23

1 Answers1

4

Because all activities are contexts, but not all contexts are activities. I think the ImageView was not created from an activity.

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • You are rigth. I created the ImageView from the application context instead from the context of the activity. Thank you! – Adrian Feb 07 '11 at 17:49