Adrian
Adrian

Reputation: 719

ClassCastException when casting an ImageView context to an Activity

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?

Upvotes: 0

Views: 1374

Answers (1)

Cristian
Cristian

Reputation: 200080

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

Upvotes: 4

Related Questions