This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showInputDialog problem

 
kunagu varun
Ranch Hand
Posts: 38
  • 0
  • 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: 2475
8
  • 0
  • 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
  • 0
  • 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: 2475
8
  • 0
  • 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: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic