java - 为什么 JOptionPane 不接受这个字符串?
问题描述
我的 JOptionPane 中显示 String msg3 时遇到问题。运行时出现“字符串无法转换为 int”错误。如果将 3 个不同的字符串分隔到它们自己的窗格中,程序将运行,但是,我需要它们都在同一个窗格中。感谢您提前提供任何建议/帮助。
//add all of the expenses together
double total = airfare1 + carRent1 + parking1 + reg1 + (lodge1 * numberOfDays1) + (meals * numberOfDays1);
String msg1;
msg1 = String.format("Total cost: $%,.2f\n Allowed expenses: $%,.2f\n", total);
//Calculate the allowable reinbusement
double allow = airfare1 + carRent1 + ( pfees * numberOfDays1) + reg1 + (lfees * numberOfDays1) + (meals * numberOfDays1);
String msg2;
msg2 = String.format("Allowed expenses: $%,.2f\n", allow);
//calculates the total amount to be paid back
double pback = total - allow;
String msg3;
msg3 = String.format("Amount to be paid back: $%,.2f\n", pback);
//display the totals using joptionpane
JOptionPane.showMessageDialog(null,msg1,msg2,msg3);
解决方案
您传递 msg3 的参数是字符串,但方法接受整数。没有从String到int的直接转换。
推荐阅读
- javascript - 谷歌云平台从标签管理器获取请求
- sql - STUFF Microsoft Access 中的语法错误
- angular - Angular 路由器导航更改 url,但不呈现组件
- r - 从数据框中选择基于特定条件的多个条目,R中有很多垃圾文本
- c# - C# 使用 LINQ 更改 ComboBox 项的选定索引
- python - 从 python 中的 CANVAS 中抓取文本
- python - 循环不会遍历列表
- ios - 无法将“颜色”类型的值分配给“UIColor”类型
- java - 如何将 LocalTime 正确格式化为 HH:MM?
- node.js - 在使用 npm 的 VS 代码方面需要帮助