【发布时间】:2012-02-06 03:56:15
【问题描述】:
我在我的 android 应用程序中收到以下错误:
表达式的类型必须是数组类型,但解析为 int
protected void onListItemClick(ListView lv, View v, int position, long id) {
super.onListItemClick(lv, v, position, id);
String openClass = R.array.calc_categories[position]; //error on this line
try {
Class selected = Class.forName("com.calculator.commonCalculatios." + openClass);
Intent selectedIntent = new Intent(this, selected);
startActivity(selectedIntent);
【问题讨论】:
-
听起来
calc_categories是int而不是数组。 -
我父亲很久以前就教过我,“不要与编译器争论”。编译器会告诉你究竟出了什么问题。你认为
calc_categories是一个数组,但它实际上是一个int。如果这没有意义,是时候研究一些代码了。祝你好运!