Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help please

 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep on having an "Application Error" on my game whenever I try to run it on my phone. When I click "Details" it shows "NullPointerException". However, when I am running on my computer, it doesn't display any message like that. Why is that?

I want to post my code here but it's more than 400 lines of code.

Help me please, thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We had had a similar issue before. While I can't give you a direct answer because you give us very little to go on.

But sometimes the devices implement the specification in different ways, and hence one device might give you a NullPointerException, while the other won't show you that even though one exists.

Have you tried to debug it through the Wireless Toolkit and an IDE?

Also look at your code and see where you call a method on an instance of some object, and put in a check for null.

Mark
 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's my code for that. I cleaned some part of it and replaced it with comments to cut it short.

here's my code "NewGame.java"



It's pretty long, isn't it
I'll appreciate your help very much. Thanks.
[ July 13, 2005: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, we'll put CODE tags around your code so that we can see formatting and read it.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, some comments.

1. Why do you have a Graphics g; instance variable. It is never used, nor should it be. Only use the Graphics class that is in the paint method. I see that you pass it to other methods, which I guess is ok for your purposes.

2. The bigger one, and NOT THE source for a NullPointerException



(edited to protect the innocent, namely me.)
Let alone that display is part of your MIDlet, and should be in that class, not in a Canvas class. You are too tightly coupling classes this way.

Mark
[ July 13, 2005: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other comments.

1. You are not following Sun's coding standards. The open curly braces are in the wrong place.

OK, I see where your assign your display variable, but still say that it shouldn't be in your Canvas class. A canvas class should just be what is displayed on the screen and nothing else. No logic for how the game is played, no MIDlet controlling stuff. Just drawing the screen.

2. OK, could paint be called before you ever assign a value to the image variable?

3. Also, why are you using an png file for each letter in the alphabet instead of drawing letters where you want them. Then you don't need all the keyCode checking stuff, sort of. Actually not sure.

Mark
 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for editing the presentation of my "cut & pasted" code.

For that display.setCurrent(this), I have to set the current display to show the things I have here. Actually, the current display is set to the main midlet and I transfered it here. When I remove it, it wouldn't show the game board that I have created inside this class.
 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hahaha

Well, I used drawChar first. Unfortunately, the smallest font won't fit inside the box. The screen of my phone (Nokia 3220) is not enough eventhough I set it to full screen. I have to fit 1 letter inside a 1 small box.

Here's some metrics that I used before I shifted:

small font = 10x10 pixels (I assumed this)
1 letterbox = 12x12

result: the screen of my phone is not enough to display all of the boxes.
solution: I have to create images. hehehe so that I can shrink my letterbox size to 11x11 and make the letters appear 9x9.



 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a short description of the game board:

The game board is composed of 2 4x8 letterboxes.
width = 4 letterboxes, height = 8 letterboxes.
1 4x8 on the left and 1 on the right.
Left and Right are separated distance equal to width of 1 letterbox.

--
| | 1 letterbox = 12x12 pixels
--

**** **** * = 1 letterbox
**** **** -> this a miniature size of my gameboard
**** ****
**** ****
**** ****
**** ****
**** ****
**** ****

Note: If I'll use the metrics, this game board won't fit my screen.


 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post the exact error message you get with the NullPointerException? It should include the line number that causes the exception. (At least it does in J2SE apps. I'm rather new to J2ME myself, so I don't am still figuring out these kinds of details as well.) If it gives the line number, please indicate which one it is.

Layne
 
ram vikram
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

try to create the images which are necessary in the constructor .

and keep the try {} catch statements . in paint and keypressed and also in constructor.

and also check to see that may be your are accesing any variables before the creation of Object instance.
 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layne,

Hi, the problem is that there are no error numbers because the error appears on my phone and not while it's being played on the pc. However, I think I already know where the problem is.

Windows didn't see it as an error because it doesn't care whether "A.PNG" is equal to "a.png", get it? But when it's already deployed to run on the phone, that makes a whole lot of difference.

I'm also new to this and thanks to people like Mark, I can pause for a while and ask someone who can make me reflect on my code.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic