Android: java.lang.ClassCastException: android.widget.imageView cannot be cast to android.widget.textView Android: java.lang.ClassCastException: android.widget.imageView cannot be cast to android.widget.textView xml xml

Android: java.lang.ClassCastException: android.widget.imageView cannot be cast to android.widget.textView


Eclipse tends to mess up your resources every now and then.This leads to some odd behavior such as strings and images being swapped all over your app, and more commonly classCastException(s), which happen when Eclipse switches your Views' ids around.

A few solutions to that problem:

Clean your project.

Modify an xml layout file and save.

Delete your R file. (Don't worry it will be automatically generated again).

Basically anything that makes your project rebuild and re-generate the R file.


Just clean up your project and everything will be fine.


Some times this problem shows because we have created ImageView But Cast with Image Button as like this

 <ImageView        android:id="@+id/iv_thumb"        android:layout_width="50dip"        android:layout_height="50dip"        />  holder.imageView = (ImageButton) convertView.findViewById(R.id.iv_thumb);

we have declared Imageview but cast to ImageButton, for this reason also have face this problem.