Results 1 to 9 of 9
  1. #1
    David55 is offline Member
    Join Date
    Apr 2007
    Posts
    8
    Rep Power
    0

    Default Illegal Start of an Expression

    4/16/07

    Hi,
    I hope you can help me?
    I have been working with j2me mobile phone code for just a few months now and had done a few very simple game examples from a book I am using.
    The game I am working on now is more complex for me and I am asking for some help on it.
    Game description;
    It is a game where the character goes through a maze and if the character collides with the walls there is tone and 10 points are subtracted from the score(you start with a 100 points) that is displayed while the game is played.
    I did not use the RMS(Record Management System) because I wanted to keep it very simple and not list many score at the same time on display.
    The problem I am having is in the Sun Emulator build process where these errors are displayed.
    Project "SavethePrincess1Canvas" loaded
    Project settings saved
    Building "SavethePrincess1Canvas"
    D:\java VM\apps\SavethePrincess1Canvas\src\SavethePrincess 1Canvas.java:228: illegal start of
    expression
    private void draw(Graphics g) {
    ^
    D:\java VM\apps\SavethePrincess1Canvas\src\SavethePrincess 1Canvas.java:247: ';' expected

    ^
    2 errors
    com.sun.kvem.ktools.ExecutionException
    Build failed
    Here is my complete code;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    import java.util.*;
    import java.io.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;

    public class SavethePrincess1Canvas extends GameCanvas implements Runnable {
    private Display display;
    private boolean sleeping;
    private long frameDelay;
    private int inputDelay;
    private LayerManager layers;
    private int xView, yView;
    private TiledLayer BackgroundMapLayer;
    private TiledLayer BarrierMapLayer;
    private Sprite General;
    private Player musicPlayer;


    public SavethePrincess1Canvas(Display d) {
    super(true);
    display = d;

    // Set the frame rate (30 fps)
    frameDelay = 33;

    // Clear the input delay
    inputDelay = 0;

    }

    public void start() {
    // Set the canvas as the current screen
    display.setCurrent(this);


    // Create the BackgroundMap and BarrierMap tiled layers
    try {
    BackgroundMapLayer = new TiledLayer(18,19,Image.createImage("/BackgroundMap.png"),10,10);
    BarrierMapLayer = new TiledLayer(18,19, Image.createImage("/BarrierMap.png"),10,10);
    }
    catch (IOException e) {
    System.err.println("Failed loading images!");
    }

    // Setup the Background tiled layer map
    int[] BackgroundMap = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
    19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
    37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
    55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
    73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
    91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
    109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
    127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
    145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
    163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
    181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
    199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
    217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
    235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
    253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270,
    271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
    289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
    307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
    325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,

    };

    for (int i = 0; i < BackgroundMap.length; i++) {
    int column = i % 18;
    int row = (i - column) / 19;
    BackgroundMapLayer.setCell(column, row, BackgroundMap[i]);
    }

    // Setup the BarrierMap tiled layer map
    int[] BarrierMap = {
    1, 0, 3, 4, 0, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 16, 0, 18,
    19, 0, 21, 22, 0, 24, 25, 0, 0, 0, 29, 30, 0, 0, 0, 0, 0, 36,
    37, 38, 39, 40, 0, 42, 43, 0, 45, 46, 47, 48, 0, 50, 51, 52, 53, 54,
    55, 0, 57, 58, 0, 60, 61, 0, 63, 64, 65, 66, 0, 68, 69, 0, 0, 72,
    73, 0, 75, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86, 87, 0, 0, 90,
    91, 0, 93, 94, 95, 96, 97, 98, 99, 0, 101, 102, 0, 104, 0, 0, 0, 108,
    109, 0, 0, 0, 0, 114, 115, 0, 0, 0, 119, 120, 0, 122, 0, 124, 125, 0,
    127, 0, 0, 0, 0, 132, 133, 0, 0, 0, 137, 138, 0, 0, 0, 142, 143, 0,
    145, 0, 147, 148, 0, 150, 151, 0, 153, 154, 155, 156, 0, 158, 159, 160, 161, 162,
    163, 0, 165, 166, 0, 168, 169, 0, 171, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    181, 0, 183, 184, 0, 186, 187, 0, 189, 0, 191, 192, 193, 194, 195, 196, 197, 198,
    199, 0, 201, 202, 0, 0, 0, 0, 207, 0, 0, 0, 0, 212, 213, 0, 0, 216,
    217, 218, 219, 220, 0, 222, 223, 224, 225, 0, 0, 0, 229, 230, 231, 0, 0, 0,
    235, 236, 237, 238, 0, 240, 241, 242, 243, 0, 245, 246, 247, 248, 249, 0, 251, 252,
    253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 269, 270,
    271, 0, 273, 274, 275, 276, 277, 0, 0, 280, 281, 282, 283, 284, 285, 286, 287, 288,
    289, 0, 291, 292, 293, 294, 295, 0, 0, 298, 299, 300, 301, 302, 303, 304, 305, 306,
    307, 0, 0, 0, 0, 312, 313, 0, 0, 0, 317, 318, 0, 0, 0, 0, 0, 0,
    325, 326, 327, 328, 0, 330, 331, 0, 0, 0, 335, 336, 0, 338, 339, 340, 341, 342,


    };

    for (int i = 0; i < BarrierMap.length; i++) {
    int column = i % 18;
    int row = (i - column) / 19;
    BarrierMapLayer.setCell(column, row, BarrierMap[i]);
    }


    // Initialize the General
    try {
    General = new Sprite(Image.createImage("/General.png"), 6, 7);
    }
    catch (IOException e) {
    System.err.println("Failed loading images!");
    }

    // Create the layer manager
    layers = new LayerManager();
    layers.append(General);
    layers.append(BarrierMapLayer);
    layers.append(BackgroundMapLayer);
    xView = (BackgroundMapLayer.getWidth() - getWidth()) / 2;
    yView = (BackgroundMapLayer.getHeight() - getHeight()) / 2;
    layers.setViewWindow(xView, yView, getWidth(),getHeight());

    General.setPosition(xView+(getWidth()-General.getWidth()) /2,
    yView + (getHeight() - General.getHeight()) / 1);

    // Initialize and start the music player
    try {
    InputStream is = getClass().getResourceAsStream("Collide.wav");
    musicPlayer = Manager.createPlayer(is, "audio/x wav");
    musicPlayer.prefetch();
    musicPlayer.setLoopCount(1);
    musicPlayer.start();
    }
    catch (IOException ioe) {
    }
    catch (MediaException me) {
    }

    // Start the animation thread
    sleeping = false;
    Thread t = new Thread(this);
    t.start();

    }

    public void stop() {
    // Close the music player
    musicPlayer.close();
    }

    public void run() {
    Graphics g = getGraphics();

    // The main game loop
    while (!sleeping) {
    update();
    draw(g);
    try {
    Thread.sleep(frameDelay);
    }
    catch (InterruptedException ie) {}
    }

    }


    private void update() {
    // Process user input to move the General
    if (++inputDelay > 0) {
    int keyState = getKeyStates();
    int xMove = 0, yMove = 0;
    if ((keyState & LEFT_PRESSED) != 0)
    xMove = -1;
    else if ((keyState & RIGHT_PRESSED) != 0)
    xMove = 1;
    if ((keyState & UP_PRESSED) != 0)
    yMove = -1;
    else if ((keyState & DOWN_PRESSED) != 0)
    yMove = 1;
    if (xMove != 0 || yMove != 0) {
    layers.setViewWindow(xView + xMove, yView + yMove, getWidth(), getHeight());
    General.move(xMove, yMove);
    }
    // Check for a collision with the General and the BarrierMap tiled layer
    if (General.collidesWith(BarrierMapLayer, true)) {
    // Play a collision sound
    try {
    Manager.playTone(ToneControl.C4 + 2, 100, 100);
    }
    catch (Exception e) {
    }

    // Restore the original view window and General positions
    layers.setViewWindow(xView, yView, getWidth(), getHeight());
    General.move(-xMove, -yMove);
    }
    }
    // Reset the input delay
    inputDelay = 0;
    }
    private void draw(Graphics g) {
    // Draw the layers
    layers.paint(g, 0, 0);
    // Flush the offscreen graphics buffer
    flushGraphics();

    }
    }
    For the pass several weeks I have tried to analogize the errors but I am having a difficult time understanding it.
    I would greatly appreciate if you could give me some suggestions on how to correct this.
    Thank you,
    David Brown

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Hi Brown

    I consider this as a simple compile error, But I tried copying it to the eclipse and to see that there is something wrong ,But I couldn't find any. Can't you try with some other method name ? Once again make sure you are using the same source code for compilation.

    thanks
    goldhouse

  3. #3
    levent Guest

    Default

    Hi Brown,

    Are you sure you are using correct file name while compiling or somewhere in configuration of Sun Emulator?

    Because as far as i see, there is a space between "SavethePrincess" and "1Canvas.java" but there should not be space there:

    D:\java VM\apps\SavethePrincess1Canvas\src\SavethePrincess 1Canvas.java:228: illegal start of ...

  4. #4
    sandor is offline Member
    Join Date
    Apr 2007
    Location
    Pennsylvania,USA
    Posts
    45
    Rep Power
    0

    Default

    What happens if you make the method in question public instead of private?

  5. #5
    David55 is offline Member
    Join Date
    Apr 2007
    Posts
    8
    Rep Power
    0

    Default

    4/28/07
    Hi,
    I want to thank you very much for the prompt respond to my email.
    You are correct.The program I sent you does work.I sent you the wrong one.
    I hope you can help me?
    I have been working with j2me mobile phone code for just a few months now and had done a few very simple game examples from a book I am using.
    The game I am working on now is more complex for me and I am asking for some help on it.
    Game description;
    It is a game where the character goes through a maze and if the character collides with the walls there is tone and 10 points are subtracted from the score(you start with a 100 points) that is displayed while the game is played.
    I did not use the RMS(Record Management System) because I wanted to keep it very simple and not list many score at the same time on display.
    The problem I am having is in the Sun Emulator build process where these errors are displayed.
    Project "SavethePrincess1Canvas" loaded
    Project settings saved
    Building "SavethePrincess1Canvas"
    D:\java VM\apps\SavethePrincess1Canvas\src\SavethePrincess 1Canvas.java:231: illegal start of
    expression
    private void paint(Graphics g) {
    ^
    D:\java VM\apps\SavethePrincess1Canvas\src\SavethePrincess 1Canvas.java:251: ';' expected
    ^
    2 errors
    com.sun.kvem.ktools.ExecutionException
    Build failed
    Here is my complete code;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    import java.util.*;
    import java.io.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    public class SavethePrincess1Canvas extends GameCanvas implements Runnable {
    private Display display;
    private boolean sleeping;
    private long frameDelay;
    private int inputDelay;
    private LayerManager layers;
    private int xView, yView;
    private TiledLayer BackgroundMapLayer;
    private TiledLayer BarrierMapLayer;
    private Image InfoBar;
    private Sprite General;
    private Player musicPlayer;
    private int Score;
    public SavethePrincess1Canvas(Display d) {
    super(true);
    display = d;
    // Set the frame rate (30 fps)
    frameDelay = 33;
    // Clear the input delay
    inputDelay = 0;
    }
    public void start() {
    // Set the canvas as the current screen
    display.setCurrent(this);
    //Initialize the game variables
    Score = 100;
    // Create the BackgroundMap and BarrierMap tiled layers
    try {
    infoBar = Image.createImage("/InfoBar.png");
    BackgroundMapLayer = new TiledLayer(18,19,Image.createImage("/BackgroundMap.png"),10,10);
    BarrierMapLayer = new TiledLayer(18,19, Image.createImage("/BarrierMap.png"),10,10);
    }
    catch (IOException e) {
    System.err.println("Failed loading images!");
    }
    // Setup the Background tiled layer map
    int[] BackgroundMap = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
    19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
    37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
    55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
    73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
    91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
    109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
    127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
    145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
    163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
    181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
    199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
    217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
    235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
    253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270,
    271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
    289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
    307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
    325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342,
    };
    for (int i = 0; i < BackgroundMap.length; i++) {
    int column = i &#37; 18;
    int row = (i - column) / 19;
    BackgroundMapLayer.setCell(column, row, BackgroundMap[i]);
    }
    // Setup the BarrierMap tiled layer map
    int[] BarrierMap = {
    1, 0, 3, 4, 0, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 16, 0, 18,

    };
    for (int i = 0; i < BarrierMap.length; i++) {
    int column = i % 18;
    int row = (i - column) / 19;
    BarrierMapLayer.setCell(column, row, BarrierMap[i]);
    }
    // Initialize the General
    try {
    General = new Sprite(Image.createImage("/General.png"), 6, 7);
    }
    catch (IOException e) {
    System.err.println("Failed loading images!");
    }
    // Create the layer manager
    layers = new LayerManager();
    layers.append(General);
    layers.append(BarrierMapLayer);
    layers.append(BackgroundMapLayer);
    xView = (BackgroundMapLayer.getWidth() - getWidth()) / 2;
    yView = (BackgroundMapLayer.getHeight() - getHeight()) / 2;
    layers.setViewWindow(xView, yView, getWidth(),getHeight());
    General.setPosition(xView+(getWidth()-General.getWidth()) /2,
    yView + (getHeight() - General.getHeight()) / 1);
    // Initialize and start the music player
    try {
    InputStream is = getClass().getResourceAsStream("Collide.wav");
    musicPlayer = Manager.createPlayer(is, "audio/x wav");
    musicPlayer.prefetch();
    musicPlayer.setLoopCount(1);
    musicPlayer.start();
    }
    catch (IOException ioe) {
    }
    catch (MediaException me) {
    }
    // Start the animation thread
    sleeping = false;
    Thread t = new Thread(this);
    t.start();
    }
    public void stop() {
    // Close the music player
    musicPlayer.close();
    }
    public void run() {
    Graphics g = getGraphics();
    // The main game loop
    while (!sleeping) {
    update();
    draw(g);
    try {
    Thread.sleep(frameDelay);
    }
    catch (InterruptedException ie) {}
    }
    }
    private void update() {
    // Process user input to move the General
    if (++inputDelay > 0) {
    int keyState = getKeyStates();
    int xMove = 0, yMove = 0;
    if ((keyState & LEFT_PRESSED) != 0)
    xMove = -1;
    else if ((keyState & RIGHT_PRESSED) != 0)
    xMove = 1;
    if ((keyState & UP_PRESSED) != 0)
    yMove = -1;
    else if ((keyState & DOWN_PRESSED) != 0)
    yMove = 1;
    if (xMove != 0 || yMove != 0) {
    layers.setViewWindow(xView + xMove, yView + yMove, getWidth(),
    getHeight() - InfoBar.getHeight());
    General.move(xMove, yMove);
    }
    // Check for a collision with the General and the BarrierMap tiled layer
    if (General.collidesWith(BarrierMapLayer[i], true)) {
    // Play a collision sound
    try {
    Manager.playTone(ToneControl.C4 + 2, 100, 100);
    }
    catch (Exception e) {
    }
    //Decrease the General Lives
    Score -= 10;
    // Restore the original view window and General positions
    layers.setViewWindow(xView, yView, getWidth(),
    getHeight() - InfoBar.getHeight());
    General.move(-xMove, -yMove);
    }
    else {
    // If there is no collision,commit the changes to the view window position
    xView += xMove;
    yView += yMove;
    }
    for (int i = 0; i > 10; i++) {
    // Update the General and the BarrierMap
    General.update();
    Barrier[i].update();
    // Reset the input delay
    inputDelay = 0;
    }
    private void paint(Graphics g) {
    // Draw the InfoBar and numLives
    g.drawImage(InfoBar, 0, 0, Graphics.TOP | Graphics.LEFT);
    g.setColor(0, 0, 0); // black
    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
    g.drawString("Score:", 88, 1, Graphics.TOP | Graphics.LEFT);
    for (int i = 0; i > Score; i++)
    g.setColor(255, 255, 255); // white
    g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    g.fillRect(40, 3, numLIves, 12);
    // Draw the layers
    layers.paint(g, 0, InfoBar.getHeight());
    // Flush the offscreen graphics buffer
    flushGraphics();
    }
    I had to shorten the BarrierMap program in order for it to fit in the email.
    I want to add Score to my game and for the pass several weeks I have tried to analogize the
    errors but I am having a difficult time understanding it.
    I would greatly appreciate if you could give me some suggestions on how to correct this.
    Thank you,
    David Brown

  6. #6
    JavaBiatch is offline Member
    Join Date
    Oct 2007
    Posts
    4
    Rep Power
    0

    Default

    i think you forgot a "}"

    Here
    .....
    for (int i = 0; i > 10; i++) {
    // Update the General and the BarrierMap
    General.update();
    Barrier[i].update();
    // Reset the input delay
    inputDelay = 0;
    }
    }
    private void paint(Graphics g) {
    // Draw the InfoBar and numLives
    g.drawImage(InfoBar, 0, 0, Graphics
    ...

    Just add another "}" after the for loop and everything should be fine.

  7. #7
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    Congratulations, you answered to a 6 month old thread :)

  8. #8
    JavaBiatch is offline Member
    Join Date
    Oct 2007
    Posts
    4
    Rep Power
    0

    Default

    It's the time it took me to figure it what was the problem ;)

  9. #9
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    It's the time it took me to figure it what was the problem
    haha. it is better than never..

Similar Threads

  1. illegal character: \65279
    By iwax in forum New To Java
    Replies: 3
    Last Post: 01-30-2008, 02:52 PM
  2. Replies: 9
    Last Post: 08-08-2007, 07:16 PM
  3. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM
  4. Boolean Expression
    By ritwik07 in forum New To Java
    Replies: 3
    Last Post: 07-11-2007, 04:11 AM
  5. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-20-2007, 05:59 AM

Posting Permissions

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