Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Strings in switch are not supported in source 1.5...

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Strings in switch are not supported in source 1.5...

    I am creating a checkers game and im trying to paint the board but it says the switch is using a string, but its actually not. Here is the code

    public void paintComponent(Graphics g) {


    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if ( row % 2 == col % 2 )
    g.setColor(Color.LIGHT_GRAY);
    else
    g.setColor(Color.GRAY);
    g.fillRect(2 + col*20, 2 + row*20, 20, 20);
    switch (board.pieceAt(row,col)) {
    case CheckersData.RED:
    g.setColor(Color.RED);
    g.fillOval(4 + col*20, 4 + row*20, 15, 15);
    break;
    }
    }

    And this is the method it calls

    int pieceAt(int row, int col) {
    return board[row][col];
    }

    Any help would be much appreciated.
    Last edited by glennder; February 2nd, 2012 at 12:52 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    If you want help, you'll have to provide an SSCCE (not your whole program) that demonstrates exactly what's going on. As of now we'd just be guessing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    switch (board.pieceAt(row,col)) {

    That is the line it crashes on,
    the pieceAt method is below

    int pieceAt(int row, int col) {
    return board[row][col];
    }

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    If you want help, you'll have to provide an SSCCE (not your whole program) that demonstrates exactly what's going on. As of now we'd just be guessing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    I reposted the shortend version

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    It's not just a matter of shortening it- did you read the link I gave you on what an SSCCE should be? It should be short, but it should also be self-contained (so we can just copy and paste it without adding anything) and compilable (in your case, it should show the same compiler error).

    As of now we have no idea what much of your code is doing. We don't have time to go through your whole program, so it's your job to shorten it up to a self-contained example. Actually, in the process of creating an SSCCE, you'll end up figuring out the problem yourself!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    Ah i see, i got it working now anyways thanks.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Strings in switch are not supported in source 1.5...

    What was the problem?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. IF and SWITCH Statements: How and When to Use Them
    By snowguy13 in forum Java Programming Tutorials
    Replies: 2
    Last Post: January 11th, 2012, 10:46 AM
  2. Java Security Implementation for Plugin Supported Architecture
    By bgroenks96 in forum Java Theory & Questions
    Replies: 19
    Last Post: November 22nd, 2011, 04:13 PM
  3. IllegalArgumentException: Pan not supported
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 13th, 2010, 01:00 PM
  4. Switch Statment
    By 3XiLED in forum Java Theory & Questions
    Replies: 2
    Last Post: March 31st, 2010, 05:11 PM
  5. Jsp source not found
    By jadeite100 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 15th, 2010, 01:00 AM