Results 1 to 2 of 2
  1. #1
    Civie is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default Comparing a character with characters within a string

    When I run the applet that uses this piece of code I get the following error:
    ALERT: java/lang/ClassFormatError: Bad version information.


    public void checkInput()
    {
    //variables
    char gletter = 'x';
    String sword;

    //split String into stringArray
    char[] stringArray;
    stringArray = sword.toCharArray();

    readyDataframe();

    //set receiver

    //compare chars
    byte[] swordBytes = sword.getBytes();

    for(int i = 0; i < sword.length; i++)
    {
    if(i < swordBytes.length)
    {
    if(byte[i] swordBytes comparesTo gletter) <---byte gives a syntax error (I really don't know what I actually have to put here, I've tried multiple things like string and char. swordBytes gives a 'cannot be resolved to a type' error. [i] gives an error saying I need to place a ")".
    {
    frame[i+14] = gletter;
    }
    }
    }

    //send frame
    }

    If someone could explain what I am doing wrong, it would be highly appreciated.

  2. #2
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    Try some System.out.println() statements in your for-loop to see what is stored in your variables.

    When I was starting out, here is what I used MANY TIMES to troubleshoot array and loop issues :

    for(int i=0;i<var.length;i++){
    System.out.println(var[i]);
    }

    I hope this helps!
    Chris :)
    Last edited by tashimoto; 10-21-2010 at 08:17 PM. Reason: Added a "troubleshooting" for-loop

Similar Threads

  1. Replies: 8
    Last Post: 02-22-2014, 09:06 AM
  2. Comparing JComboBox with string?
    By vahshir in forum New To Java
    Replies: 2
    Last Post: 10-10-2010, 08:39 AM
  3. Comparing contents of a file with String[]
    By eponcedeleon in forum Advanced Java
    Replies: 2
    Last Post: 02-25-2010, 10:10 PM
  4. how to get next character/string
    By doha786 in forum New To Java
    Replies: 3
    Last Post: 03-28-2009, 05:04 AM
  5. comparing array using character
    By Anseki in forum New To Java
    Replies: 7
    Last Post: 10-03-2008, 08:28 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
  •