Results 1 to 2 of 2
  1. #1
    narasimha is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default How to run TiledLayer in midp 2.0 of j2me

    hi....every one
    I need help of you to run tiledlayer in j2me.when i run below program it is saying IlligalStateExcepion.so i unable to run this program.so plz kindly help me.

    I written program as like below

    import java.io.IOException;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;



    public class SpriteCollideMIDlet extends MIDlet {

    SpriteCollideCancas canvas = new SpriteCollideCancas();

    public SpriteCollideMIDlet(){ }

    protected void destroyApp(boolean some) throws MIDletStateChangeException{ }

    protected void pauseApp() { }

    protected void startApp()throws MIDletStateChangeException {

    Display display = Display.getDisplay(this);

    canvas.start();

    display.setCurrent(canvas);
    }
    }

    class SpriteCollideCancas extends GameCanvas implements Runnable {

    static int FRONT_DIRECTION = 0;

    static int LEFT_DIRECTION = 1;

    static int RIGHT_DIRECTION = 2;

    static int BACK_DIRECTION = 3;

    Sprite hero,hero2;

    boolean running;

    int[][] sequence = {{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};

    int s2[] ={8,9,10,11};

    int w,h;

    Image img_bg = null;

    int cx,cy,cx2,cy2;

    int currentDirection = FRONT_DIRECTION;

    protected SpriteCollideCancas() {

    super(true);

    Image im = null,hm2 = null;

    try{


    im = Image.createImage("/grid.png");
    hm2 = Image.createImage("/grid1.png");

    img_bg = Image.createImage("/kodim22.png");

    }catch(IOException e){ }

    hero = new Sprite(im,8,10);

    hero2 = new Sprite(hm2,8,10);

    w = getWidth();
    h = getHeight();

    cx = w/2;
    cy = h/2;

    hero.setFrameSequence(sequence[0]);
    hero2.setFrameSequence(s2);
    }

    public void start(){

    running = true;

    Thread t = new Thread(this);

    t.start();
    }
    public void run(){

    Graphics g =getGraphics();

    int delay=100;

    while(running){

    moving();

    getInput();

    hero2.nextFrame();
    drawScreen(g);
    try{

    Thread.sleep(delay);
    }catch(InterruptedException e){}
    }
    }
    void moving(){

    if(cx2>getWidth()){
    cx2=0;
    }
    if(!hero2.collidesWith(hero,false))
    cx2++;
    }
    void getInput(){

    int keyState = getKeyStates();

    int cDirection = currentDirection;

    if(keyState==LEFT_PRESSED){

    if(!hero.collidesWith(hero2,false)){

    cx=cx-5;cx=Math.max(0,cx);
    currentDirection=LEFT_DIRECTION;
    }hero.nextFrame();
    }else if(keyState==RIGHT_PRESSED){

    cx=cx+5;cx=Math.min(cx,w-32);
    currentDirection=RIGHT_DIRECTION;
    hero.nextFrame();
    }else if(keyState==UP_PRESSED){

    cy=cy-5;cy=Math.max(0,cy);
    currentDirection=BACK_DIRECTION;
    hero.nextFrame();
    }else if(keyState==DOWN_PRESSED){

    cy=cy-5; cy=Math.min(cy,h-50);
    currentDirection=FRONT_DIRECTION;
    hero.nextFrame();
    }

    if(cDirection!=currentDirection){

    hero.setFrameSequence(sequence[currentDirection]);
    }
    }

    void drawScreen(Graphics g){

    g.drawImage(img_bg,0-cx,0-cy,Graphics.TOP|Graphics.LEFT);

    hero2.setPosition(cx2,cy2+20);
    hero2.paint(g);
    hero.setPosition(cx,cy);
    hero.paint(g);
    flushGraphics();
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    when i run below program it is saying IlligalStateExcepion.
    Post the stack trace and indicate which line of code is causing the Exception.

    db

Similar Threads

  1. Replies: 1
    Last Post: 08-07-2009, 10:30 AM
  2. MIDP web browser
    By islamfunny in forum CLDC and MIDP
    Replies: 0
    Last Post: 10-07-2008, 12:22 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
  •