Two Laptop Bag
The moose likes Beginning Java and the fly likes problem with converting to double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with converting to double" Watch "problem with converting to double" New topic

problem with converting to double

Jessica Madden

Joined: Nov 02, 2003
Posts: 1
I am having a problem with this program I am writing and I was wondering if anyone can help. Here is the part that is getting an error:
eof = false;
while (!eof){
name = br.readLine();
if (name == null){
eof = true;
} else {
sWeeklySales = br.readLine();
weeklySales = Double.parseDouble(sWeeklySales);
if (weeklySales >= 2000){
commRate = 5.0/100;
numEarnComm = numEarnComm + 1;
msg = "";
} else {
commRate = 0;
numNotEarnComm = numNotEarnComm + 1;
msg = msg + "*";
}//end if

commSales = weeklySales * commRate;
weeklyPay = commSales + baseSalary;
totComm = totComm + commSales;

It says "Process Complete" but when I run it, it says:
Exception in thread "main" java.lang.NullPointerException
at java.lang.FloatingDecimal.readJavaFormatString(
at java.lang.Double.parseDouble(
at Haberdasher.main(
Press any key to continue...
Does anyone know why it isn't accepting the conversion? thanks
[ November 02, 2003: Message edited by: Jessica Madden ]
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

As the Exception pointed out, it was a NullPointer exception.
You check the name after br.readLine() for null value, but didn't
do the same with the sWeeklySales string.
[ November 02, 2003: Message edited by: Wirianto Djunaidi ]
I agree. Here's the link:
subject: problem with converting to double
It's not a secret anymore!