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?

1
  • You should never, ever, do that. I don't see a single legitimate reason to cast anything to an (Activity) Commented Feb 7, 2011 at 17:23

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

You are rigth. I created the ImageView from the application context instead from the context of the activity. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.