为什么 JOptionPane 不接受这个字符串?

问题描述 投票:0回答:1

我在 JOptionPane 中显示 String msg3 时遇到了问题。当运行时,我得到一个 "String cannot be converted to 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);
java joptionpane
1个回答
0
投票

请参阅官方文档

你传给msg3的参数是字符串,但方法接受整数。没有直接从 字符串.

© www.soinside.com 2019 - 2024. All rights reserved.