错误:类型不匹配:无法从void转换为java.lang.String

时间:2016-10-02 00:50:32

标签: android

我一直收到此错误:

  

类型不匹配:我无法从void转换为java.lang.String   对话框。

我试图在对话框中显示计算名称但我得到上面的错误。

 public static void main(String[] args)
  {
   final double tax_Rate = .08;
   final double bonus_Pay_Rate = .1;
   String name = JOptionPane.showInputDialog("Please enter your name");
   String hr = JOptionPane.showInputDialog("Please enter your hourly rate");
   double  hourlyRate = Double.parseDouble(hr);
   String hw = JOptionPane.showInputDialog("Please enter your hours worked");
   double hoursWorked = Double.parseDouble(hw);
   double tax = (hoursWorked * hourlyRate) * tax_Rate;
   double pay = hoursWorked * hourlyRate - tax;
   double weeksPay = (pay * bonus_Pay_Rate) + pay;
   String aswner = JOptionPane.showMessageDialog(null, (name) + "'s" + "pay this week is: $" + (weeksPay));

1 个答案:

答案 0 :(得分:0)

您正在尝试将void分配给字符串。

String aswner = JOptionPane.showMessageDialog(null,... );

showMessageDialog会返回void,而非String

https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html