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

标签 java android arrays

我的 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);

最佳答案

你可能想要这样的东西:

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

关于java - 表达式的类型必须是数组类型,但它解析为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155423/

相关文章:

android - 您可以在 Android Marshmallow (API 23) 的运行时权限模型中同步请求权限吗?

android - ProGuard 在我的应用程序中不起作用

python - 查找一个数组中的哪些元素与另一个数组中的任何元素接近的最有效方法是什么?

java - 在 DropWizard 或 Jetty 应用程序中导致 404 的日志 URL

java - 通过 CMD 与 Powershell 执行 Java 命令时的差异 - 由句点 ("."引起)

android - 如何为 MediaCodec 设置平均+最大比特率来编码 H.264 视频?

javascript - 使用javascript合并数组中具有间隔属性的重叠对象

Python-循环遍历未排序的数组时计算某一项的出现次数

java - App Engine Blobstore - 如何限制用户可以上传的文件的大小?

java - 带有 JTable 的 JScrollpane 中的背景图像