Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:JOptionPane.showOptionDialog_Java - Fatal编程技术网

Java 错误:JOptionPane.showOptionDialog

Java 错误:JOptionPane.showOptionDialog,java,Java,伙计们,我一直在做作业,我只有一个错误。我没有任何想法来解决这个问题,所以你可以帮助我,或者如果你有建议,就编辑我的代码。错误为“类型JOptionPane中的方法showOptionDialog(组件、对象、字符串、int、int、图标、对象[]、对象)不适用于参数(null、字符串、int、int、null、对象[]、对象)” 下面是我的代码 import javax.swing.JOptionPane; import java.util.Scanner; public class FLA

伙计们,我一直在做作业,我只有一个错误。我没有任何想法来解决这个问题,所以你可以帮助我,或者如果你有建议,就编辑我的代码。错误为“类型JOptionPane中的方法showOptionDialog(组件、对象、字符串、int、int、图标、对象[]、对象)不适用于参数(null、字符串、int、int、null、对象[]、对象)”

下面是我的代码

import javax.swing.JOptionPane;
import java.util.Scanner;

public class FLABWORK3_ABUEL
{
  static Scanner Scan = new Scanner (System.in);
  public static void main(String[]  args)
  {
  String choice;
  String num1;
  String string;
  String Inverse;

  int choicee, num2, response, length;
  double squareroot;

  Object[] options = {"Yes", "No"};

  do {
      choice = JOptionPane.showInputDialog("Main Menu" + 
  "\n 1. Square of a number" +
  "\n 2. Square root a number" +
  "\n 3. Cube of a number" +
  "\n 4. Length of number" +
  "\n 5. Inverse of a String");

      choicee = Integer.parseInt(choice);

      while (choicee > 5)
      {
          choice = JOptionPane.showInputDialog("Enter only 1-5!");
      }

      if (choicee == 1)
      {
        num1 = JOptionPane.showInputDialog("Enter an number.");
        num2 = Integer.parseInt(num1);
        num2 = num2*num2 ;
        JOptionPane.showMessageDialog(null, "The square of the number: " + num2);

    } else if (choicee == 2)
    {
        num1 = JOptionPane.showInputDialog("Enter a number.");
        squareroot = Integer.parseInt(num1);
        squareroot = Math.sqrt(squareroot);
        JOptionPane.showMessageDialog(null, "Square root is: " + squareroot);

    } else if (choicee == 3)
    {
        num1 = JOptionPane.showInputDialog("Enter a number.");
        num2 = Integer.parseInt(num1);
        num2 = num2*(num2*num2);
        JOptionPane.showMessageDialog(null, "The cube is: " + num2);

    } else if (choicee == 4) 
    {
        string = JOptionPane.showInputDialog("Enter a sentence or a word.");
        length = string.length();
        JOptionPane.showMessageDialog(null, "The length :  " + "\n" + length + "\n\n" +
          "is:" + string);

    }
    else if (choicee == 5)
    {
        string = JOptionPane.showInputDialog("Enter a word.");
        length = string.length();
        for (int i = length - 1; i >= 0; i--)
              Inverse = Inverse + string.charAt(i);
    }

        response = JOptionPane.showOptionDialog(null,
                  "Would you like to try again?",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.QUESTION_MESSAGE,null, options, options[0]);

  }
  while (response == JOptionPane.YES_OPTION);
}
}您的参数数量不正确。以下是showOptionDialog的结构:

showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)

try response=JOptionPane.showConfirmDialog(null,“是否重试”,“标题”,JOptionPane.YES\u NO\u选项)@我试过了,但没用。我也试着匹配那些仍然不起作用的论点。谢谢!sytanx错误消失了,但出现了另一个错误,它表示Inverse=Inverse+string.charAt(i);局部变量逆可能未初始化