为什么JOptionPane不接受此字符串?

时间:2020-04-22 20:59:10

标签: java joptionpane

我在JOptionPane中显示字符串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);

1 个答案:

答案 0 :(得分:1)

See the official documentation

您通过ms​​g3传递的参数是String,但是方法接受整数。从 String int 没有直接转换。