| Reply | « Previous Thread | Next Thread » |
|
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) {} } } |
|
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 |
|
Quote:
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) {} } } } |
|
From your code it seems that your LayerManager instance is not initialized anywhere. A line like this should be present:
Code:
lm = new LayerManager(); Pit |
|
Quote:
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()); } |
|
Hi soofika,
are you calling your init() method somewhere in your code (it's not called in the code you've posted)? Pit |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| receive question SMS / modify it on PC / and send answer SMS to same number | pawwaw | General Messaging | 8 | 2007-10-10 07:00 |
| a question about command and a question about s60 | t4kesting | Mobile Java General | 0 | 2006-01-24 09:21 |
| May be this is a stupid question | lpinguin | Mobile Java General | 1 | 2006-01-05 09:50 |
| can't use any simulator in NMIT 3.1 (stupid question) | chan_chun_man | General Browsing | 2 | 2003-04-29 14:29 |
| i'm using the nokia mobile internet toolkit 3.1, and i have a question | tinduc | General Messaging | 0 | 2003-04-07 10:52 |