如何解决ClassCastException错误?

时间:2018-03-04 07:30:20

标签: java android string classcastexception

我有一个错误:

  

FATAL EXCEPTION:主程序:com.example.sjdav.searchfilterlist,   PID:6394                                                                                     java.lang.ClassCastException:java.lang.String无法强制转换为   com.example.sjdav.searchfilterlist.StringObj                                                                                         在   com.example.sjdav.searchfilterlist.ValueAdapter.getView(ValueAdapter.java:80)

data = readlines("text.txt") data = lowercase.(data) data = replace.(data, [r"""[,.:;?!()]"""], [""]) 中的内容:

ValueAdapter

public class ValueAdapter extends BaseAdapter implements Filterable { private static final String TAG = "ValueAdapter"; private ArrayList<StringObj> mStringList; private ArrayList<StringObj> mStringFilterList; private LayoutInflater mInflater; private ValueFilter valueFilter; private Context mContext; private int mResource; private int lastPosition = 1; public ValueAdapter(@NonNull Context context, int resource, ArrayList<StringObj> stringObjs) { this.mContext = context; this.mResource = resource; this.mStringList = stringObjs; this.mStringFilterList = mStringList; mInflater = LayoutInflater.from(context); getFilter(); } // How many items are in the data set represented by this Adapter. @Override public int getCount() { return mStringList.size(); } //Get the data item associated with the specified position in the data set. @Override public Object getItem(int position) { return mStringList.get(position); } //Get the row id associated with the specified position in the list. @Override public long getItemId(int position) { return position; } private class Holder { TextView textView1; ImageView imageView1; } //Get a View that displays the data at the specified position in the data set. @Override public View getView(int position, View convertView, ViewGroup parent) { // Setup Image Loading setUpImageLoader(); Log.i(TAG, "getView: VA >> Image Loader complete.."); <!-- HERE --> String name = mStringList.get(position).getName(); String imgURL = mStringList.get(position).getImgURL(); 类:

StringObj

我原本以为将名称变量转换为public class StringObj { public String name; public String imgURL; public StringObj(String name, String imgURL) { this.name = name; this.imgURL = imgURL; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getImgURL() { return imgURL; } public void setImgURL(String imgURL) { this.imgURL = imgURL; } } 并从String ArrayList获取一个字符串(其中包含两个字符串)会没问题吗?我显然不明白这里发生了什么,所以有人可以帮忙吗?谢谢!

0 个答案:

没有答案