开发者

ClassCastException when casting an ImageView context to an Activity

开发者 https://www.devze.com 2023-02-09 05:59 出处:网络
I don\'t understand why I\'m receiving a ClassCastException when I use this line: Activity a=(Activity)photoToLoad.imageView.getConte开发者_如何学Goxt();

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

Activity a=(Activity)photoToLoad.imageView.getConte开发者_如何学Goxt();

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消