[ Post New Message | Post Reply to this One | Send Private Email to Cliff Wirt | Help ]

Dreaded Null Pointer Exceptions (Java)

from Cliff Wirt (DementedMagpie@hotmail.com)
I am working through Who's Afraid of Java. In doing one of the exercises, I wrote a DrugStockItem class, a derived class, PrescriptionDrugItem, and an application program. All three compiled successfully. But when I ran the application, I got a NullPointerException message. The code that is causing the problem is certainly this:

void DeductSaleFromInventory(int QuantitySold) { String EnterPassword = ""; System.out.println("Password?"); EnterPassword = RWVar.readString(System.in); if (m_Password.equals(EnterPassword)) m_InStock -= QuantitySold; else System.out.println("Access Denied. Wrong Password."); }

Why is this code fine with the compiler, but causes Java to choke at runtime? Any suggestions?

I couldn't get the compiler on the CD to work (perhaps because I had already downloaded the compiler from the Sun web site). So the compiler I am using is jdk1_1_8.

(posted 6838 days ago)

[ Previous | Next ]