JOptionPane错误没有为showMessageDialog找到合适的方法(<null>,String,int)</null>

时间:2015-01-19 21:44:02

标签: java swing jbutton actionlistener joptionpane

以下是代码:

class ButtonHearerer implements ActionListener
{

  public void actionPerformed(ActionEvent event)
  {
     ///////////////

     if ( event.getSource() == overviewButton )
     {
        welcomeJPanel.setVisible(false);

        overviewJPanel.setVisible(true);

        get.add ( overviewJPanel );

     }
     /////////////////

     else 

        if ( event.getSource() == infoButton )
        {
           JOptionPane.showMessageDialog(null,
                "<html>"
              + "<tr><th>ID INFORMATION</th><tr><table style ='border:2px solid black'>"
              + "<tr><td halign='left'>Programmer</td><td align=center width = 200px>:</td><td align=right>Mohamed Ahmed</td></tr>"
              + "<tr><td halign='left'>Assignment #</td><td align=center width = 200px>:</td><td align=right>Final Project</td></tr>"
              + "<tr><td halign='left'>Assignment Name</td><td align=center width = 200px>:</td><td align=right>The Final Escape</td></tr>"
              + "<tr><td halign='left'>Course # and Title</td><td align=center width = 200px>:</td><td align=right>CISC 190 - Java</td></tr>"
              + "<tr><td halign='left'>Instructor</td><td align=center width = 200px>:</td><td align=right>Professor Forman</td></tr>"
              + "<tr><td halign='left'>Hours</td><td align=center width = 200px>:</td><td align=right>MW 9:35 - 12:45</td></tr>"
              + "<tr><td halign='left'>Difficulty</td><td align=center width = 200px>:</td><td align=right>9</td></tr>"
              + "<tr><td halign='left'>Completion Date</td><td align=center width = 200px>:</td><td align=right>05/21/14</td></tr>"
              + "<tr><td halign='left'>Program Name</td><td align=center width = 200px>:</td><td align=right>MohamedsFinalRevised</td></tr></table>"
              +"</html>",
              "ID Info",
              JOptionPane.PLAIN_MESSAGE);

        }

        //////////////

        else 

           if ( event.getSource() == acctBalButton )
           {

           String  playersDeposit  = deposit.getText(); 

           doubleDeposit  = Double.parseDouble(playersDeposit);

           String acctBalText  =  accountBalance(acctBalTxt);

           acctBalance = doubleDeposit - totalFee;

           String  playersAlias  = alias.getText();                                                   

           JOptionPane.showMessageDialog(null,"Account Balance", "<html>THE GREATEST ESCAPE ACCOUNT BALANCE\n"
                  + "===================================="
                  + "\n\n Summary of" + name + "Account for"
                  + "alias of" + playersAlias + ":"
                  + "\n"+ moneyFormatter.format(playersDeposit) 
                  + " in the THE GREATEST ESCAPE GAME IN THE WORLD"
                  + "- Total ESCAPE Registration Fee\n"
                  + moneyFormatter.format(totalFee)
                  + "- Total Escape Registration Fee\n"
                  + "=====\n"
                  + moneyFormatter.format(acctBalance)
                  + "- Current Account Balance\n\n"
                  + "HAVE A NICE DAY...</html>",
                  JOptionPane.PLAIN_MESSAGE);

           }

所以我刚刚更新了代码并运行了它,但是当我触摸按钮时,我收到了错误:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number
    at java.text.DecimalFormat.format(DecimalFormat.java:507)
    at java.text.Format.format(Format.java:157)
    at MohamedsFinalRevised.accountBalance(MohamedsFinalRevised.java:1252)
    at MohamedsFinalRevised$ButtonHearerer.actionPerformed(MohamedsFinalRevised.java:1338)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

2 个答案:

答案 0 :(得分:1)

JOptionPane需要组件,标题,消息,图标)如果我在代码中正确看到,你只需给它3个参数。

看看

  

Examples on Displaying dialogs

     

Documentation

试试这个:

JOptionPane.showMessageDialog(YourClass.this,"Title" ,"<html>THE GREATEST ESCAPE ACCOUNT BALANCE\n"
                  +"===================================="
                  +"\n\n Summary of" + name + "Account for"
                  +"alias of" + playersAlias + ":"
                  +"\n"+ moneyFormatter.format(playersDeposit) 
                  +" in the THE GREATEST ESCAPE GAME IN THE WORLD"
                  +"- Total ESCAPE Registration Fee\n"
                  +moneyFormatter.format(totalFee)
                  +"- Total Escape Registration Fee\n"
                  +"=====\n"
                  +moneyFormatter.format(acctBalance)
                  +"- Current Account Balance\n\n"
                  +"HAVE A NICE DAY...</html>",
                  JOptionPane.PLAIN_MESSAGE);

答案 1 :(得分:1)

对第一个参数

使用新的JFrame()而不是null