java - 据我所知,showinputdialog 返回字符串类型的输出,但它给了我一个错误,它无法将对象转换为字符串
问题描述
String val = JOptionPane.showInputDialog(null,
"Search item to Edit ",
"Warning",
JOptionPane.QUESTION_MESSAGE,
null,
new String[]{"Item name", "Item no.","Price"},
"");
错误:
不兼容的类型:对象不能转换为字符串
解决方案
有了这么多参数,该方法showInputDialog
不会返回一个字符串,而是一个对象,如javadoc中所述
正如Swing 教程中所建议的,您只需将结果转换为字符串。
String val = (String) JOptionPane.showInputDialog(null,
"Search item to Edit ",
"Warning",
JOptionPane.QUESTION_MESSAGE,
null,
new String[]{"Item name", "Item no.","Price"},
"");
推荐阅读
- docker - 添加 jar 后 Kubernetes Pod 崩溃
- python - 如何从python中的行中删除字母和空格?
- java - Vertx 3.9.0 是否支持 Redis Json?还有其他方法可以实现吗?
- numpy - Numpy叉积矩阵函数
- postgresql - PostgreSQL COPY 管道输出到 gzip 然后到 STDOUT
- flutter - 无法在 Firebase 存储上收听
- sharepoint - 基于另一个字段选择的 Sharepoint 隐藏/显示列不起作用
- jenkins - 在自由式作业中选择 git 分支的选择参数
- laravel - 在空 laravel 删除条件的加载模型
- r - 当列达到一定数量的行时,0 值将值更改为 Na