单击列表查看项目错误 @ ID #0x5?
我收到错误“未找到资源异常:字符串资源 ID #0x5”。我知道它与 i.putExtra(...) 有关。我试图从数据库列“gotoURL”中提取一个字符串,以将 URL 字符串从 ListView 中的 listItem 传递到 WebView 活动。任何帮助PLZ!谢谢!
我的活动:
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> a, View v, int position,long id)
{
Object o = lv.getItemAtPosition(position);
Toast.makeText(List_AC.this, "Clicked!", Toast.LENGTH_LONG).show();
Intent i = new Intent(List_AC.this, DocView.class);
Cursor cursor = Adapter_AC.dataCursor;
i.putExtra("url", getString(cursor.getColumnIndexOrThrow("gotoURL")));
startActivity(i);
}
});
适配器:
public class Adapter_AC extends SimpleCursorAdapter {
static Cursor dataCursor;
private LayoutInflater mInflater;
public Adapter_AC(Context context, int layout, Cursor dataCursor,
String[] from, int[] to) {
super(context, layout, dataCursor, from, to);
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.label);
holder.text2 = (TextView) convertView.findViewById(R.id.listTitle);
holder.text3 = (TextView) convertView.findViewById(R.id.caption);
holder.text4 = (TextView) convertView.findViewById(R.id.dummy);
holder.text4.setVisibility(View.GONE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
dataCursor.moveToPosition(position);
int label_index = dataCursor.getColumnIndex("label");
String label = dataCursor.getString(label_index);
int title_index = dataCursor.getColumnIndex("title");
String title = dataCursor.getString(title_index);
int description_index = dataCursor.getColumnIndex("description");
String description = dataCursor.getString(description_index);
int goto_index = dataCursor.getColumnIndex("gotoURL");
String gotoURL = dataCursor.getString(goto_index);
holder.text1.setText(label);
holder.text2.setText(title);
holder.text3.setText(description);
holder.text4.setText(gotoURL);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
TextView text3;
TextView text4;
protected static final String KEY_TITLE = "text4";
}
}
I get an error 'Resources Not Found Exception: String resource ID #0x5. I know it has to do with the i.putExtra(...). I am trying to pull a string from a DB column 'gotoURL' to pass a URL string from a listItem in my ListView to a WebView Activity. Any help PLZ! Thnx!
Im my Activity:
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> a, View v, int position,long id)
{
Object o = lv.getItemAtPosition(position);
Toast.makeText(List_AC.this, "Clicked!", Toast.LENGTH_LONG).show();
Intent i = new Intent(List_AC.this, DocView.class);
Cursor cursor = Adapter_AC.dataCursor;
i.putExtra("url", getString(cursor.getColumnIndexOrThrow("gotoURL")));
startActivity(i);
}
});
The Adapter:
public class Adapter_AC extends SimpleCursorAdapter {
static Cursor dataCursor;
private LayoutInflater mInflater;
public Adapter_AC(Context context, int layout, Cursor dataCursor,
String[] from, int[] to) {
super(context, layout, dataCursor, from, to);
this.dataCursor = dataCursor;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.label);
holder.text2 = (TextView) convertView.findViewById(R.id.listTitle);
holder.text3 = (TextView) convertView.findViewById(R.id.caption);
holder.text4 = (TextView) convertView.findViewById(R.id.dummy);
holder.text4.setVisibility(View.GONE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
dataCursor.moveToPosition(position);
int label_index = dataCursor.getColumnIndex("label");
String label = dataCursor.getString(label_index);
int title_index = dataCursor.getColumnIndex("title");
String title = dataCursor.getString(title_index);
int description_index = dataCursor.getColumnIndex("description");
String description = dataCursor.getString(description_index);
int goto_index = dataCursor.getColumnIndex("gotoURL");
String gotoURL = dataCursor.getString(goto_index);
holder.text1.setText(label);
holder.text2.setText(title);
holder.text3.setText(description);
holder.text4.setText(gotoURL);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
TextView text3;
TextView text4;
protected static final String KEY_TITLE = "text4";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能出在 onItemClickListner 中:
您请求列索引(整数),将其用作 Context.getString() 的输入,该 Context.getString() 期望这是一个(现有)资源 ID。从你的错误中我可以猜测“gotoURL”的columnIndex是5并且不存在这样的资源id...
我猜你真正想要放入意图的是“gotoURL”列的字符串值,就像你在适配器?
The problem could be in the onItemClickListner:
You ask for the columnindex (an integer), use it as input to the Context.getString() that expects this to be an (existing) Resource ID. From your error I can guess that the columnIndex for "gotoURL" is 5 and no such resource id exists...
I guess what you really want to put in the intent is the string value for the column "gotoURL" as you do it in the adapter?