You Are Here:

Community: Developer Discussion Boards

#1 Old LayerManger - probably a stupid question - 2008-09-15, 18:14

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
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) {}
}
}
Reply With Quote

#2 Old Re: LayerManger - probably a stupid question - 2008-09-15, 18:18

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
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


www.jappit.com - mobile and web blog
Reply With Quote

#3 Old Re: LayerManger - probably a stupid question - 2008-09-15, 18:24

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
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) {}
}

}

}
Reply With Quote

#4 Old Re: LayerManger - probably a stupid question - 2008-09-15, 18:32

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
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


www.jappit.com - mobile and web blog
Reply With Quote

#5 Old Re: LayerManger - probably a stupid question - 2008-09-15, 18:52

Join Date: Nov 2007
Posts: 42
soofika
Offline
Registered User
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());
}
Reply With Quote

#6 Old Re: LayerManger - probably a stupid question - 2008-09-15, 22:32

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
Hi soofika,

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

Pit


www.jappit.com - mobile and web blog
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ