| | |
Java Null Pointer Exception
Thread Solved
![]() |
•
•
Join Date: Feb 2007
Posts: 27
Reputation:
Solved Threads: 1
Hi I'm trying to write a multi-formed J2ME app. I keep getting a null pointer exception in the startApp() method.
I have currentForm created above and the first is mapped to it, (with the plan of mapping each new from to currentForm.
I have login set up, so I'm really confused why I getting this error.
Everything above has been declared as usual. Any suggestions as to what I'm doing wrong?
Thanks, chuck
Java Syntax (Toggle Plain Text)
public void startApp() { display.setCurrent(currentForm); }
I have currentForm created above and the first is mapped to it, (with the plan of mapping each new from to currentForm.
Java Syntax (Toggle Plain Text)
private Form currentForm, login; //etc
Java Syntax (Toggle Plain Text)
currentForm = login;
I have login set up, so I'm really confused why I getting this error.

Java Syntax (Toggle Plain Text)
loginTF = new TextField[2]; loginTF[0] = new TextField("Staff Number:", "", 10, TextField.NUMERIC); loginTF[1] = new TextField("Password:", "", 50, TextField.PASSWORD); login = new Form("login", loginTF); login.addCommand(submit); login.addCommand(exit); login.addCommand(clear); login.setCommandListener(this);
Everything above has been declared as usual. Any suggestions as to what I'm doing wrong?
Thanks, chuck
Nel sogni, come in amore, non ci sono cose impossible
Maybe the NullPointerException refers to "display".
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2007
Posts: 27
Reputation:
Solved Threads: 1
Nope, sadly not. It's set up as usual:
Thanks, any other ideas?
Java Syntax (Toggle Plain Text)
Display display; //... display = Display.getDisplay(this);
Thanks, any other ideas?
Last edited by mr.sweetchuck; Mar 1st, 2007 at 1:56 pm.
Nel sogni, come in amore, non ci sono cose impossible
Some more code is needed. According to the method showed (in a cupsule like it was) display definately would be null, since there is no evidence otherwise. Post the entire class.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2007
Posts: 27
Reputation:
Solved Threads: 1
It's a pretty big class, but I'll try to cut out the irrevelant parts.
Java Syntax (Toggle Plain Text)
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MyClient extends MIDlet implements CommandListener { /*********************Widget declarations***************************************/ private Display display; private Form currentForm, main, login; //more, but not relivant private StringItem options[]; private TextField loginTF[], cleanUpTF[], patientBill[], wardInfo[], patientDetails[]; private TextField securityDetails[], securityTF[], medAlertTF[]; private Command exit, select, clear, submit, remove, mainMenu, first; private Command previous, next, last, generateBill, findPatient, update, report; /****************************Constructor****************************************/ public void myClient() { display = Display.getDisplay(this); /**************************Commands*********************************************/ //comands initialised /********************Login Screen***********************************************/ loginTF = new TextField[2]; loginTF[0] = new TextField("Staff Number:", "", 10, TextField.NUMERIC); loginTF[1] = new TextField("Password:", "", 50, TextField.PASSWORD); login = new Form("login", loginTF); login.addCommand(submit); login.addCommand(exit); login.addCommand(clear); login.setCommandListener(this); currentForm = login; } /*********************Displaying The First Screen*******************************/ public void startApp() { display.setCurrent(currentForm); } /*********************Pausing The Application***********************************/ public void pauseApp() {} /**************************Destroying The Application***************************/ public void destroyApp(boolean unconditional) {} } /******************************End of Class*************************************/
Last edited by mr.sweetchuck; Mar 2nd, 2007 at 1:07 pm. Reason: removing irelivant code
Nel sogni, come in amore, non ci sono cose impossible
What about the Class Display.
Is it at all possible that
Please provide this getDisplay method, or if it comes from some thrid party API, then please provide the JavaDoc from this method.
Is it at all possible that
display = Display.getDisplay(this); returns null?Please provide this getDisplay method, or if it comes from some thrid party API, then please provide the JavaDoc from this method.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
And that says nothing. Those classes are those classes, this class is this class. If you do not wish to provide the info we would need to help you, then at least don't waste our time.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2007
Posts: 27
Reputation:
Solved Threads: 1
Display comes from:
javax.microedition.lcdui.Display
Which is a default class that the compiler recognises and I have not over-written.
The api is available on:
http://kickjava.com/3205.htm#33462
This is what the api says:
This is what I did:
javax.microedition.lcdui.Display
Which is a default class that the compiler recognises and I have not over-written.
The api is available on:
http://kickjava.com/3205.htm#33462
This is what the api says:
This is what I did:
Java Syntax (Toggle Plain Text)
class MyClass extends MIDlet { ... Display display; Form currentForm,login; TextField loginTF[]; ... public void MyClass { display = Display.getDisplay(this); ... loginTF = new TextField[2]; loginTF[0] = new TextField("Staff Number:", "", 10, TextField.NUMERIC); loginTF[1] = new TextField("Password:", "", 50, TextField.PASSWORD); login = new Form("login", loginTF); ... currentForm = login; } ... public void startApp() { display.setCurrent(currentForm); }
Nel sogni, come in amore, non ci sono cose impossible
According to the documentation for Form and Display, and if this is actually the line throwing the null pointer exception, then display is the only thing that even can be null, since the setCurrent method will accept a null value, so currentForm is allowed to be null.
Take out all the dots and attempt to run the Class exactly as it is portrayed here. If that works, then the problem lies somewhere else in your code. Maybe there is some process somewhere in your class that sets display to null again. I don't know since I can't see the rest of the code.
As I said, however, reading the Display and Form API pages from this lcdui package, indicates that display is the only thing in that line that even could cause a NullPointerExcpetion.
Take out all the dots and attempt to run the Class exactly as it is portrayed here. If that works, then the problem lies somewhere else in your code. Maybe there is some process somewhere in your class that sets display to null again. I don't know since I can't see the rest of the code.
As I said, however, reading the Display and Form API pages from this lcdui package, indicates that display is the only thing in that line that even could cause a NullPointerExcpetion.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- null pointer exception problem (Java)
- help with sort using Calendar class getting null pointer exception (Java)
Other Threads in the Java Forum
- Previous Thread: PLEASE HELP, Duplication in Arrays
- Next Thread: Java run time enviorment
| Thread Tools | Search this Thread |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows






