2017-08-06 90 views
0

Im新的Java和即时通讯有麻烦与下面的代码。我试图将一个双变量转换为一个字符串变量在JOptionPane.showMessagedialog中使用它,但它给了我一个下面列出的错误。在JOptionPane中插入一个双变量

import javax.swing.JOptionPane; 
public class pricecalculatorchap5 

{ 
    public static void main(String [] args) 

    { 
     String priceinput; 
     double wholesaleprice; 
     double markupprice; 
     double retailprice; 
     String retailprice2; 
     String pricecalculated; 

    priceinput = JOptionPane.showInputDialog("Please enter the whole sale price of the item."); 
    wholesaleprice = Double.parseDouble(priceinput); 


      priceinput = JOptionPane.showInputDialog("Please enter the markeup price of the item."); 
      markupprice = Double.parseDouble(priceinput); 


    retailprice = ((markupprice/100) * wholesaleprice) + wholesaleprice; 
    retailprice2 = Double.toString (retailprice); 



    pricecalculated = JOptionPane.showMessageDialog("The price of the item is calculated as " + retailprice2); 


    } 
}  

ERROR

pricecalculatorchap5.java:28: error: no suitable method found for showMessageDialog(String) pricecalculated = JOptionPane.showMessageDialog("The price of the item is calculated as " + retailprice2);
^ method JOptionPane.showMessageDialog(Component,Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable (actual and formal argument lists differ in length) 1 error

回答

0

showMessageDialog总是以Component在一起。有许多方法重写,但没有一个只有你使用的String参数。 Refer Document