【问题标题】:The type of the expression must be an array type but it resolved to int表达式的类型必须是数组类型,但解析为 int
【发布时间】: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_categoriesint 而不是数组。
  • 我父亲很久以前就教过我,“不要与编译器争论”。编译器会告诉你究竟出了什么问题。你认为calc_categories 是一个数组,但它实际上是一个int。如果这没有意义,是时候研究一些代码了。祝你好运!

标签: java android arrays


【解决方案1】:

你可能想要这样的东西:

String openClass = getResources().getStringArray(R.array.calc_categories)[position]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-20
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多