×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    LayerManger - probably a stupid question

    Any idea why I am getting a null pointer exception from the following code

    public class gCanvas extends GameCanvas implements Runnable {
    ....
    ....
    public void run() {
    while (true) {
    Graphics g = getGraphics();
    g.setColor(255,0,0);
    g.fillRect(0, 0, 100, 100); // <-- this works
    lm.paint(getGraphics(), 0, 0); // <-- exception error
    flushGraphics();
    try {
    Thread.currentThread().sleep(10);
    } catch (Exception e) {}
    }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: LayerManger - probably a stupid question

    Hi soofika,

    are you defining somewhere your 'lm' instance? From your code, it seems that it is still null when you call its paint() method.

    Pit

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    Re: LayerManger - probably a stupid question

    Quote Originally Posted by jappit View Post
    Hi soofika,

    are you defining somewhere your 'lm' instance? From your code, it seems that it is still null when you call its paint() method.

    Pit
    I think I am Pit.. but here is more complete code snippet..

    public class gCanvas extends GameCanvas implements Runnable {

    public gCanvas() {
    super(false);
    }
    private mGolf parent;
    private LayerManager lm;
    private TiledLayer tl;

    public gCanvas(final mGolf parent) {
    super(false);
    this.parent = parent;
    }

    public void init() throws IOException{
    Image bg = Image.createImage("/rsc/cop_ov.png");
    tl = new TiledLayer(1,1,bg,512,512);
    lm.append(tl);
    lm.setViewWindow(0, 0, bg.getWidth(), bg.getHeight());
    }

    public void start() throws Exception {

    // create and load Midlet
    Thread runner = new Thread(this);
    runner.start();

    }

    public void run() {
    while (true) {
    Graphics g = getGraphics();
    g.setColor(255,0,0);
    g.fillRect(0, 0, 100, 100);
    lm.paint(getGraphics(), 0, 0);
    flushGraphics();
    try {
    Thread.currentThread().sleep(10);
    } catch (Exception e) {}
    }

    }

    }

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: LayerManger - probably a stupid question

    From your code it seems that your LayerManager instance is not initialized anywhere. A line like this should be present:
    Code:
    lm = new LayerManager();
    Also, is your init() method called somewhere?

    Pit

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    42

    Re: LayerManger - probably a stupid question

    Quote Originally Posted by jappit View Post
    From your code it seems that your LayerManager instance is not initialized anywhere. A line like this should be present:
    Code:
    lm = new LayerManager();
    Also, is your init() method called somewhere?

    Pit
    That is a good catch Piit.. I added that as follows..but I am still getting the same error...

    public void init() throws IOException{
    lm = new LayerManager();
    Image bg = Image.createImage("/rsc/cop_ov.png");
    tl = new TiledLayer(1,1,bg,512,512);
    lm.append(tl);
    lm.insert(tl, 1);
    lm.setViewWindow(0, 0, getWidth(), getHeight());
    }

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: LayerManger - probably a stupid question

    Hi soofika,

    are you calling your init() method somewhere in your code (it's not called in the code you've posted)?

    Pit

Similar Threads

  1. Replies: 9
    Last Post: 2010-08-03, 07:03
  2. a question about command and a question about s60
    By t4kesting in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-24, 08:21
  3. May be this is a stupid question
    By lpinguin in forum Mobile Java General
    Replies: 1
    Last Post: 2006-01-05, 08:50
  4. Replies: 0
    Last Post: 2003-04-07, 09:52

Posting Permissions

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