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

标签 java joptionpane

我在 JOptionPane 中显示字符串 msg3 时遇到问题。运行时出现“字符串无法转换为 int”错误。如果 3 个不同的字符串被分成各自的 Pane ,程序将运行,但是,我需要它们全部位于同一个 Pane 中。感谢您提前提供的任何建议/帮助。


        //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);

最佳答案

See the official documentation

您传递的 msg3 参数是字符串,但方法接受整数。没有从 Stringint 的直接转换。

关于java - 为什么 JOptionPane 不接受这个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61375013/

相关文章:

java - 启动线程的问题

java - 如何动态设置XTextTable名称

Java - 带有ExecutorService的多线程爬虫

java - 如果条件为真,则从 JOptionPane Java 禁用 NO_BUTTON

java - JOptionPane 对话框错误

java - 如何在java中更改JScrollPane的大小

java - http ://pubsubhubbub. appspot.com/subscribe 407 需要身份验证

java - 授权不起作用(Spring Security)

java - Gridbag布局问题

java - 无法退出用于 JOptionPane 的 try-catch block