Java Null Pointer Exception

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2007
Posts: 27
Reputation: mr.sweetchuck is an unknown quantity at this point 
Solved Threads: 1
mr.sweetchuck mr.sweetchuck is offline Offline
Light Poster

Re: Java Null Pointer Exception

 
0
  #11
Mar 5th, 2007
It's really odd. It's definately not a case of display being set to null. Thanks for the help that you're giving. Here's the full code:

  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3.  
  4. public class NurseClient extends MIDlet implements CommandListener
  5. {
  6.  
  7.  
  8.  
  9. /*********************Widget declarations***************************************/
  10.  
  11.  
  12.  
  13. private Display display;
  14. private Form currentForm, main, login, cleanUp, bill, ward, patient, securityReport, security, medical;
  15. private StringItem options[];
  16. private TextField loginTF[], cleanUpTF[], patientBill[], wardInfo[], patientDetails[];
  17. private TextField securityDetails[], securityTF[], medAlertTF[];
  18. private Command exit, select, clear, submit, remove, mainMenu, first;
  19. private Command previous, next, last, generateBill, findPatient, update, report;
  20.  
  21.  
  22.  
  23. /****************************Constructor****************************************/
  24.  
  25.  
  26.  
  27. public void NurseClient()
  28. {
  29. display = Display.getDisplay(this);
  30.  
  31.  
  32.  
  33. /**************************Commands*********************************************/
  34.  
  35.  
  36.  
  37. exit = new Command("Exit", Command.EXIT, 1);
  38. mainMenu = new Command("mainMenu", Command.ITEM, 1);
  39. select = new Command("Select", Command.ITEM, 1);
  40. clear = new Command("Clear", Command.ITEM, 1);
  41. submit = new Command("Submit", Command.ITEM, 1);
  42. remove = new Command("Remove", Command.ITEM, 1);
  43. report = new Command("File Report", Command.ITEM, 1);
  44. update = new Command("Update Record", Command.ITEM, 1);
  45. findPatient = new Command("Find Patient", Command.ITEM, 1);
  46. generateBill = new Command("Generate Bill", Command.ITEM, 1);
  47. first = new Command("First", Command.ITEM, 1);
  48. previous = new Command("Previous", Command.ITEM, 1);
  49. next = new Command("Next", Command.ITEM, 1);
  50. last = new Command("Last", Command.ITEM, 1);
  51.  
  52.  
  53.  
  54. /**********************Main Menu Screen*****************************************/
  55.  
  56.  
  57.  
  58. options = new StringItem[7];
  59. options[0] = new StringItem("Options", "Options");
  60. options[1] = new StringItem("Clean Up Alert", "Clean Up Alert");
  61. options[2] = new StringItem("Security Alert", "Security Alert");
  62. options[3] = new StringItem("Patient Record", "Patient Record");
  63. options[4] = new StringItem("Bill Generation", "Bill Generation");
  64. options[5] = new StringItem("Ward Details", "Ward Details");
  65. options[6] = new StringItem("Medical Alert", "Medical Alert");
  66. main = new Form("options", options);
  67. main.addCommand(exit);
  68. main.addCommand(select);
  69. main.setCommandListener(this);
  70.  
  71.  
  72.  
  73. /********************Login Screen***********************************************/
  74.  
  75.  
  76.  
  77. loginTF = new TextField[2];
  78. loginTF[0] = new TextField("Staff Number:", "", 10, TextField.NUMERIC);
  79. loginTF[1] = new TextField("Password:", "", 50, TextField.PASSWORD);
  80. login = new Form("login", loginTF);
  81. login.addCommand(submit);
  82. login.addCommand(exit);
  83. login.addCommand(clear);
  84. login.setCommandListener(this);
  85.  
  86.  
  87.  
  88. /*******************Clean Up Screen*********************************************/
  89.  
  90.  
  91.  
  92. cleanUpTF = new TextField[2];
  93. cleanUpTF[0] = new TextField("Room:", "", 3, TextField.NUMERIC);
  94. cleanUpTF[1] = new TextField("Floor:", "", 3, TextField.NUMERIC);
  95. cleanUp = new Form("Clean Up Call", cleanUpTF);
  96. cleanUp.addCommand(submit);
  97. cleanUp.addCommand(exit);
  98. cleanUp.addCommand(clear);
  99. cleanUp.addCommand(remove);
  100. cleanUp.setCommandListener(this);
  101.  
  102.  
  103.  
  104. /**********************Patient Bill Screen**************************************/
  105.  
  106.  
  107.  
  108. patientBill = new TextField[4];
  109. patientBill[0] = new TextField("First Name:", "", 30, TextField.ANY);
  110. patientBill[1] = new TextField("Last Name:", "", 30, TextField.ANY);
  111. patientBill[2] = new TextField("Total Due:", "", 4, TextField.NUMERIC);
  112. patientBill[3] = new TextField("Balance:", "", 4, TextField.NUMERIC);
  113. bill = new Form("Patient Bills", patientBill);
  114. bill.addCommand(generateBill);
  115. bill.addCommand(mainMenu);
  116. bill.addCommand(first);
  117. bill.addCommand(last);
  118. bill.addCommand(next);
  119. bill.addCommand(previous);
  120. bill.setCommandListener(this);
  121.  
  122.  
  123.  
  124. /*********************Ward Info Screen******************************************/
  125.  
  126.  
  127.  
  128. wardInfo = new TextField[2];
  129. wardInfo[0] = new TextField("Ward No:", "", 3, TextField.NUMERIC);
  130. wardInfo[1] = new TextField("Free Beds:", "", 3, TextField.NUMERIC);
  131. ward = new Form("Ward Details", wardInfo);
  132. ward.addCommand(mainMenu);
  133. ward.addCommand(first);
  134. ward.addCommand(last);
  135. ward.addCommand(next);
  136. ward.addCommand(previous);
  137. ward.setCommandListener(this);
  138.  
  139.  
  140.  
  141. /*********************Patient Record Screen*************************************/
  142.  
  143.  
  144.  
  145. patientDetails = new TextField[7];
  146. patientDetails[0] = new TextField("First Name:", "", 30, TextField.ANY);
  147. patientDetails[1] = new TextField("Last Name:", "", 30, TextField.ANY);
  148. patientDetails[2] = new TextField("Date of Birth:", "", 20, TextField.ANY);
  149. patientDetails[3] = new TextField("Blood Type:", "", 30, TextField.ANY);
  150. patientDetails[4] = new TextField("Allergies:", "", 200, TextField.ANY);
  151. patientDetails[5] = new TextField("Current Treatment:", "", 200, TextField.ANY);
  152. patientDetails[6] = new TextField("Next of Kin:", "", 100, TextField.ANY);
  153. patient = new Form("Patient Records", patientDetails);
  154. patient.addCommand(findPatient);
  155. patient.addCommand(update);
  156. patient.addCommand(mainMenu);
  157. patient.addCommand(first);
  158. patient.addCommand(last);
  159. patient.addCommand(next);
  160. patient.addCommand(previous);
  161. patient.setCommandListener(this);
  162.  
  163.  
  164.  
  165. /**********************Security Report Screen***********************************/
  166.  
  167.  
  168.  
  169. securityDetails = new TextField[3];
  170. securityDetails[0] = new TextField("Security Alert No:", "", 5, TextField.NUMERIC);
  171. securityDetails[1] = new TextField("Call Date:", "", 12, TextField.ANY);
  172. securityDetails[2] = new TextField("Report:", "", 400, TextField.ANY);
  173. securityReport = new Form("Security Records", securityDetails);
  174. securityReport.addCommand(remove);
  175. securityReport.addCommand(update);
  176. securityReport.addCommand(mainMenu);
  177. securityReport.addCommand(first);
  178. securityReport.addCommand(last);
  179. securityReport.addCommand(next);
  180. securityReport.addCommand(previous);
  181. securityReport.setCommandListener(this);
  182.  
  183.  
  184.  
  185. /******************Security Alert Screen****************************************/
  186.  
  187.  
  188.  
  189. securityTF = new TextField[2];
  190. securityTF[0] = new TextField("Room:", "", 3, TextField.NUMERIC);
  191. securityTF[1] = new TextField("Floor:", "", 3, TextField.NUMERIC);
  192. security = new Form("Security Call", securityTF);
  193. security.addCommand(submit);
  194. security.addCommand(exit);
  195. security.addCommand(clear);
  196. security.addCommand(report);
  197. security.setCommandListener(this);
  198.  
  199.  
  200.  
  201. /*****************Medical Alert Screen******************************************/
  202.  
  203.  
  204.  
  205. medAlertTF = new TextField[2];
  206. medAlertTF[0] = new TextField("Room:", "", 3, TextField.NUMERIC);
  207. medAlertTF[1] = new TextField("Floor:", "", 3, TextField.NUMERIC);
  208. medical.addCommand(submit);
  209. medical.addCommand(exit);
  210. medical.addCommand(clear);
  211. medical.addCommand(remove);
  212. medical.setCommandListener(this);
  213.  
  214.  
  215. currentForm = new Form("");
  216. currentForm = login;
  217. }
  218.  
  219.  
  220.  
  221. /*********************Displaying The First Screen*******************************/
  222.  
  223.  
  224.  
  225. public void startApp()
  226. {
  227. display.setCurrent(currentForm);
  228. }
  229.  
  230.  
  231.  
  232. /*********************Pausing The Application***********************************/
  233.  
  234.  
  235.  
  236. public void pauseApp()
  237. {}
  238.  
  239.  
  240.  
  241. /**************************Destroying The Application***************************/
  242.  
  243.  
  244.  
  245. public void destroyApp(boolean unconditional)
  246. {}
  247.  
  248.  
  249.  
  250. /*************************Commands Functionality********************************/
  251.  
  252.  
  253.  
  254. public void commandAction(Command command, Displayable displayable)
  255. {
  256.  
  257.  
  258.  
  259. /*************************Exit**************************************************/
  260.  
  261.  
  262.  
  263. if (command == exit)
  264. {
  265. destroyApp(true);
  266. notifyDestroyed();
  267. }
  268.  
  269.  
  270.  
  271. /************************Clear**************************************************/
  272.  
  273.  
  274.  
  275. else if(command == clear)
  276. {
  277. if (currentForm == login)
  278. {
  279. loginTF[0].setString("");
  280. loginTF[1].setString("");
  281. }
  282. else if (currentForm == cleanUp)
  283. {
  284. cleanUpTF[0].setString("");
  285. cleanUpTF[1].setString("");
  286. }
  287. else if (currentForm == security)
  288. {
  289. securityTF[0].setString("");
  290. securityTF[1].setString("");
  291. }
  292. else if (currentForm == medical)
  293. {
  294. medAlertTF[0].setString("");
  295. medAlertTF[1].setString("");
  296. }
  297. }
  298.  
  299.  
  300.  
  301. /**********************Select***************************************************/
  302.  
  303.  
  304.  
  305. else if (command == select && currentForm == main)
  306. {/*
  307.   String s = options.getString(options.getSelectIndex());
  308.  
  309.   if (s == "Clean Up Alert")
  310.   {
  311.   currentForm = cleanUp;
  312.   }
  313.   else if (s == "Security Alert")
  314.   {
  315.   currentForm = security;
  316.   }
  317.   else if (s == "Patient Record")
  318.   {
  319.   currentForm = patient;
  320.   }
  321.   else if (s == "Bill Generation")
  322.   {
  323.   currentForm = bill;
  324.   }
  325.   else if (s == "Ward Details")
  326.   {
  327.   currentForm = ward;
  328.   }
  329.   else if (s == "Medical Alert")
  330.   {
  331.   currentForm = medical;
  332.   }*/
  333. }
  334.  
  335.  
  336.  
  337. /**************************Main Menu********************************************/
  338.  
  339.  
  340.  
  341. else if (command == mainMenu)
  342. {
  343. currentForm = main;
  344. }
  345. }
  346. }
  347.  
  348.  
  349.  
  350. /*******************************************************************************/
  351. /******************************End of Class*************************************/
  352. /*******************************************************************************/
Last edited by mr.sweetchuck; Mar 5th, 2007 at 10:49 am.
Nel sogni, come in amore, non ci sono cose impossible
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,426
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 258
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Java Null Pointer Exception

 
0
  #12
Mar 6th, 2007
Strange. The only thing I can suggest now, is to try running it in a debugger and observe what happens. I can't really suggest a debugger for a MIDlet as I have not tried any.

The only other suggestion is to make sure that that line is actually the one throwing an NPE.

And, as a general suggestion, to clean up the code a bit, I would move those commented parts of the constructor into their own private methods (one per commented part), and then call those methods from the constructor.
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 121
Reputation: tonakai is an unknown quantity at this point 
Solved Threads: 11
tonakai's Avatar
tonakai tonakai is offline Offline
Junior Poster

Re: Java Null Pointer Exception

 
0
  #13
Mar 6th, 2007
did you try to use netbeans mobility? you can debug your midlets there...
masijade can be right, NPE may be thrown somewhere else...

good luck
Good news, everyone!
aykutsoysal.com
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 121
Reputation: tonakai is an unknown quantity at this point 
Solved Threads: 11
tonakai's Avatar
tonakai tonakai is offline Offline
Junior Poster

Re: Java Null Pointer Exception

 
0
  #14
Mar 6th, 2007
i found your problem...

Originally Posted by mr.sweetchuck View Post
  1.  
  2. /****************************Constructor****************************************/
  3.  
  4.  
  5.  
  6. public void NurseClient()
  7. {
  8. display = Display.getDisplay(this);
this is not a constructor.... i think you put void mistakenly
Good news, everyone!
aykutsoysal.com
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,426
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 258
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Java Null Pointer Exception

 
0
  #15
Mar 6th, 2007
Originally Posted by tonakai View Post
i found your problem...



this is not a constructor.... i think you put void mistakenly

Aach. Completely overlooked that. Yes, that is the problem. And also the reason why display is null, because since that is not a constructor, display never gets initialised.

I am such a fool sometimes.
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 27
Reputation: mr.sweetchuck is an unknown quantity at this point 
Solved Threads: 1
mr.sweetchuck mr.sweetchuck is offline Offline
Light Poster

Re: Java Null Pointer Exception

 
0
  #16
Mar 6th, 2007
I don't believe it!!! Thanks, I feel like such a tool for missing that!
Nel sogni, come in amore, non ci sono cose impossible
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC