I have 2 simple different classes that one extends another. my first class is:
public class MyObject {}
without something in it.
and another:
public class People extends MyObject{
public String UserId;
public void setUserId(String userId) {
UserId = userId;
}
public String getUserId() {
return UserId;
}
}
I was going to cast myobject to people in my adapter and in onBindViewHolder method,and I could do it well and worked,as below:
@Override
public void onBindViewHolder(final RecyclerViewHolder holder, int position) {
final People people = (People) array.get(position);
//array is:ArrayList<MyObject> array
...}
but the problem is when I'm going to do this cast in the same class but in onclicklistener like this:
holder.rlsearchitem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
People people1= (People) savedPeopleArray.get(i);
//savedPeopleArray is:ArrayList<MyObject> savedPeopleArray
....
}
});
I get this error:
com.example.qa.setGet.MyObject cannot be cast to com.example.qa.setGet.People
why do I get this error even though I used this cast before and it worked?!