【发布时间】:2023-03-21 23:34:01
【问题描述】:
我无法在我的列表视图中创建意图。它给出了一个错误“无法实例化 活动 ComponentInfo" 并由 Classcastexception 引起。这里是 sn-p -
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent myIntent = new Intent(view.getContext(), Vol.class);
startActivityForResult(myIntent, 0);
}});
这是造成问题的代码部分 -
Intent myIntent = new Intent(view.getContext(), Vol.class);
startActivityForResult(myIntent, 0);
我不明白为什么它会给出 ClassCastException。请帮忙。谢谢!
【问题讨论】:
-
请将 view.getContext() 更改为 ClassName.this
-
我做到了。还是不行。还有什么建议吗?我真的很感激。
标签: android android-listview android-intent