gpt4 book ai didi

java - 无法在 Eclipse 中从 Object 转换为 int

转载 作者:行者123 更新时间:2023-12-02 04:59:02 28 4
gpt4 key购买 nike

在我的 Android 应用程序中,位于下面一行:

int add= (int) arg0.getTag();

出现错误:

Cannot cast from Object to int

当我将 int 替换为 integer 时,在下面的行中出现另一个错误:

sp = (Spinner) findViewById(add);

错误是:

The method findViewById(int) in the type Activity is not applicable for the arguments (R.integer)

请推荐我,希望得到答复。

谢谢

最佳答案

Cannot cast from Object to int

因为当前正在转换 getTag() 响应,将对象返回为 int

使用Integer.parseInt将字符串解析为Integer:

int add= Integer.parseInt(arg0.getTag().toString());

如果使用 setTag 传递 emply 或无效的 int 字符串,则还将解析行包装在 try-catch block 中以处理 ‎NumberFormatException

>

关于java - 无法在 Eclipse 中从 Object 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470961/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com