Exception in thread

I'm new here, learning Java has be somewhat frustrating for me. I'm having difficult time with this so I would appricate your help... Error message at runtime was displayed ( It has to do with trying to parse a string that is not parsable into an int ):

Exception in thread "main" java.lang.NumberFormatException: For input string: "Supreme"

at java.lang.NumberFormatException.forInputString(NumberFormatException.

java:48)

at java.lang.Integer.parseInt(Integer.java:468)

at java.lang.Integer.parseInt(Integer.java:518)

at Pizza.getDate(Pizza.java:34)

at Pizza.(Pizza.java:19)

at SpecialtyPizza.(SpecialtyPizza.java:13)

at PizzaDriver.storeDatabase(PizzaDriver.java:49)

at PizzaDriver.(PizzaDriver.java:12)

at PizzaDriver.main(PizzaDriver.java:125)

Here's my code:

//PlainPizza.java

public class PlainPizza extends Pizza{

private String[] toppings;

private int numToppings;

private final int MAX_TOPPINGS = 12;

public PlainPizza() {}

public PlainPizza(String date){

super("Plain Pizza Order", date);

//numToppings = MAX_TOPPINGS;

//toppings = new String[numToppings];

toppings = new String[MAX_TOPPINGS];

}

//adds number of topping to toppings array

public void addTopping(String topping) {

//numToppings = Integer.parseInt(toppings[toppings.length]);

//numToppings = (Integer.valueOf(toppings[toppings.length])).intValue();

toppings[numToppings] = topping;

numToppings++;

}

public double getPizzaCost() {

double pCost = 0;

final double PRICE_PLAINPIZZA = 8.00;

final double PRICE_TOPPING = 0.50;

pCost = PRICE_PLAINPIZZA + (PRICE_TOPPING * numToppings);

return pCost;

}

public String toString() {

String returnString = "";

returnString += super.toString();

returnString += "\n\tToppings: ";

int i = 0;

while(i < toppings.length && toppings != null){

returnString += toppings + " ";

i++;

}

return returnString;

}

} //end of PlainPizza class

Let me know if I need to post other class files associated with this...

Thanks

[2267 byte] By [jmichm@03a] at [2007-10-3 6:11:14]
# 1

> I'm new here, learning Java has be somewhat

> frustrating for me. I'm having difficult time with

> this so I would appricate your help... Error message

> at runtime was displayed ( It has to do with trying

> to parse a string that is not parsable into an int

> ):

>

> Exception in thread "main"

> java.lang.NumberFormatException: For input string:

> "Supreme"

> at

> java.lang.NumberFormatException.forInputString(NumberF

> ormatException.

> java:48)

> at

> java.lang.Integer.parseInt(Integer.java:468)

> at

> java.lang.Integer.parseInt(Integer.java:518)

> at Pizza.getDate(Pizza.java:34)

> at Pizza.(Pizza.java:19)

> at SpecialtyPizza.(SpecialtyPizza.java:13)

> at PizzaDriver.storeDatabase(PizzaDriver.java:49)

> at PizzaDriver.(PizzaDriver.java:12)

> at PizzaDriver.main(PizzaDriver.java:125)

>

> Here's my code:

>

The code you posted is not relevant to the error message you posted. Error messages are a stack trace, so the bottom line was the first line executed and the top line was the last line executed. In your case, the error occurred in the getDate method of the Pizza class. It doesn't look like any method in the PlainPizza class was called at all.

atmguya at 2007-7-15 0:54:47 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Also, please use the code tags when posting code. Just highlight the code and click on the code button.
atmguya at 2007-7-15 0:54:47 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

hey all

sorry folks .. if i am miss leading..

i got same issue stating can't parse "1" and threw a number format exception

the first result when i googled appeared this.

by the time i finished reading this issue i resolved !

guess how ? use trim() function before using convertion of String to int,long double etc..

prasanth_kumara at 2007-7-15 0:54:47 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...