• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showInputDialog problem

 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i am trying to do is to get a character as an input and test whether it is vowel or not. For this purpose i want to use input box to get the input..This is the actual code i am trying to run ..


I am always getting the following error
File: G:\Java Projects\simple\JSwitch.java [line: 8]
Error: G:\Java Projects\simple\JSwitch.java:8: inconvertible types
found : java.lang.String
required: char
I have also tried with the following...


Please help me....
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error: G:\Java Projects\simple\JSwitch.java:8: inconvertible types
found : java.lang.String
required: char

The method returns a String NOT a char. You can't assign a String to a char.

So assign a String to a String.
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya thank you for the response..

I have also tried by initializing it as String.. If i do it so,i cannot use the variable inside switch
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the String API for a method that will allow you to extract a char from the String.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure to check if the return value is null - if that is the case the user pressed Cancel or pressed the X. Also check if the entered string contains no characters at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic