表达式的类型必须是数组类型,但已解析为int [英] The type of the expression must be an array type but it resolved to int

查看:223
本文介绍了表达式的类型必须是数组类型,但已解析为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序中遇到以下错误:

I get the following error in my android app:

表达式的类型必须是数组类型,但解析为int

The type of the expression must be an array type but it resolved to 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);


推荐答案

您可能想要这样的东西:

You probably want something like this:

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

这篇关于表达式的类型必须是数组类型,但已解析为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆