Results 1 to 3 of 3

Thread: Char troubles

  1. #1
    diggdude is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default Char troubles

    Hello, i'm pretty new to the Java programming language and it seems I have run into a brick wall with the char type.

    I have written a program which translates a simple string of numbers into morse code. However, that part works perfectly, but my input validation seems to be incorrect in some way. I am constantly getting this message at compile time:

    Java Code: char cannot be dereferenced
            if (input.charAt(i).isDigit() == false) {
    To put this in better context, here is the rest of the code:

    Java Code:
    import javax.swing.JOptionPane;
    public class Question_1 {
        public static void main(String[] arg) {
        //Get the input
            String input = JOptionPane.showInputDialog("Enter a series of numbers: ");
            //Translate input and get rid of white space to the left and right of the string
            input = input.replaceAll("0"," -----");
            input = input.replaceAll("1"," .----");
            input = input.replaceAll("2"," ..---");
            input = input.replaceAll("3"," ...--");
            input = input.replaceAll("4"," ....-");
            input = input.replaceAll("5"," .....");
            input = input.replaceAll("6"," -....");
            input = input.replaceAll("7"," --...");
            input = input.replaceAll("8"," ---..");
            input = input.replaceAll("9"," ----.");
            input = input.trim();
            for (int i = 0; i <= input.length(); i++){
            if (input.charAt(i).isDigit() == false) {
                    JOptionPane.showMessageDialog(null,("Non numeric   characters are not a valid input"),"Error",
            //Output the results
            JOptionPane.showMessageDialog(null,("The morse code is: "+input),"Morse Code",
    Any help with this would be greatly appreciated, thanks in advance


    Something I forgot to add; the validation is checking for non numerical values in the string by iterating through each character, if found it will ouput an error message.
    Last edited by diggdude; 11-10-2009 at 04:19 PM.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    Java Code:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    diggdude is offline Member
    Join Date
    Nov 2009
    Rep Power


    Quote Originally Posted by PhHein View Post
    Java Code:
    Ah, so that's how you use that method. Thank you very much, solved.

Similar Threads

  1. Integer troubles
    By Tb0h in forum New To Java
    Replies: 11
    Last Post: 08-13-2009, 05:56 PM
  2. Gif decoding/LZW troubles
    By hellochar in forum Advanced Java
    Replies: 2
    Last Post: 07-15-2009, 12:26 AM
  3. Image troubles
    By Theodoreb in forum New To Java
    Replies: 24
    Last Post: 07-14-2009, 01:41 AM
  4. subclass troubles
    By xf021209 in forum New To Java
    Replies: 12
    Last Post: 04-21-2009, 12:46 AM
  5. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts