I'm building an app in Android Studio, in the app you can search in a SQLite database, it's not giving me any error when compiling but when it runs in the virtual device, it doesn't open, the app crash.
The Logcat says that there's an error in the cast, but I can find it:
java.lang.ClassCastException: android.view.TextureView cannot be cast to android.widget.TextView
Please note that I'm learning, so surely there's something I'm missing or wrong syntax
Here's the code:
class SearchViewHolder extends RecyclerView.ViewHolder{
public TextView name,address,email,phone;
public SearchViewHolder(View itemView){
super(itemView);
name = (TextView)itemView.findViewById(R.id.name);
address = (TextView)itemView.findViewById(R.id.address);
email = (TextView)itemView.findViewById(R.id.email);
phone = (TextView)itemView.findViewById(R.id.phone);
}
}
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder>{
private Context context;
private List<Friend> friends;
public SearchAdapter(Context context, List<Friend> friends) {
this.context = context;
this.friends = friends;
}
@Override
public SearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.layout_item,parent,false);
return new SearchViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull SearchViewHolder holder, int position) {
holder.name.setText(friends.get(position).getName());
holder.address.setText(friends.get(position).getAddress());
holder.email.setText(friends.get(position).getEmail());
holder.phone.setText(friends.get(position).getPhone());
}
@Override
public int getItemCount() {
return friends.size();
}
}
Any advice?
Check your layout_item
xml. There you should have mistakenly defined TextView
as TextureView
at least one time.