首页 > 解决方案 > error: no suitable method found for showInputDialog(,String,int,,String[],String)

问题描述

I'm trying to create a fraction calculator in java, I'm using the drop box int Joptionpane to display the arithmetic operations, but I keep getting an error whenever I compile the code.

String [] sChoice = {"+","-","*","/"};
            JComboBox<String> jcb = new
            JComboBox<>(sChoice);
            String input = (String)JOptionPane.showInputDialog(null,"Choise your opperator",
            JOptionPane.INFORMATION_MESSAGE,null,sChoice,sChoice[0]);

Heres the full error I'm getting.

.java:47: error: no suitable method found for showInputDialog(,String,int,,String[],String) String input = (String)JOptionPane.showInputDialog(null,"Choise your opperator", ^ method JOptionPane.showInputDialog(Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showInputDialog(Object,Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showInputDialog(Component,Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showInputDialog(Component,Object,Object) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showInputDialog(Component,Object,String,int) is not applicable (actual and formal argument lists differ in length) method JOptionPane.showInputDialog(Component,Object,String,int,Icon,Object[],Object) is not applicable (actual and formal argument lists differ in length)

标签: java

解决方案


Could you please add the formatted stack trace.

Number of arguments might be the issue.

Try changling like this, for example

JOptionPane.showInputDialog(null, " " , "txt");

推荐阅读