Question: I get a following error: ( boild line below ) The method showMessageDialog(Component, Object, String, int) in the type JOptionPane is not applicable for the

I get a following error: ( boild line below )

The method showMessageDialog(Component, Object, String, int) in the type JOptionPane is not applicable for the arguments (null, int, String, int)

so how to solve it ? please help me when I run no think happend

Time class in eclipse IDE

package time;

import java.util.Scanner; import javax.swing.JOptionPane; public class Time { public static void main(String[] args) { try { String time = JOptionPane.showInputDialog(null, "Enter a time in the format hh:mm:ss", "Enter Time", JOptionPane.QUESTION_MESSAGE); int totalSeconds = getTotalSeconds(time); JOptionPane.showMessageDialog(null, totalSeconds, "Total Seconds", JOptionPane.INFORMATION_MESSAGE); } catch(StringIndexOutOfBoundsException e) { JOptionPane.showMessageDialog(null, "You entered the time in the wrong format. " + "Please enter the time in the form hh:mm:ss", "Invalid Time", JOptionPane.ERROR_MESSAGE); } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null, "You entered an invalid time. Please enter numbers only.", "Invalid Time", JOptionPane.ERROR_MESSAGE); } catch(Exception e) { System.out.println("An unexpected Exception occurred"); } }

public static int getTotalSeconds(String time)throws NumberFormatException, StringIndexOutOfBoundsException { int hours = getTotalHours(time); //we will eventually multiply the hours by 3600 + the minutes by 60 + the seconds int minutes = getTotalMinutes (time); int seconds = getSeconds(time); return hours * 3600 + minutes * 60 + seconds; } public static int getSeconds(String time) throws NumberFormatException, StringIndexOutOfBoundsException { return Integer.parseInt(time.substring(6,8)); }

public static int getTotalMinutes(String time) throws NumberFormatException, StringIndexOutOfBoundsException { if (time.length()>8) { throw new NumberFormatException("your time was too long!"); } return Integer.parseInt(time.substring(3,5)); }

public static int getTotalHours(String time)throws NumberFormatException, StringIndexOutOfBoundsException { return Integer.parseInt(time.substring(0,2)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!