(I'm new to Java so please forgive my ignorance).
I have a very simple class:
public class Bill {
private String Total;
private int Tip;
private int People;
Bill() {
Total = "0";
Tip=0;
People=0;
}
Bill (String total, int people, int tip) {
Total = total;
Tip = tip;
People = people;
}
//the problem is here somewhere.
private Double Split = (Double.parseDouble(Total) * ((double)Tip / 100)) / (double)People;
public String getTotal() {
return Total;
}
public double getSplit() {
return Split;
}
public double getTip() {
return Tip;
}
}
When I call the 'getSplit()' method, the runtime crashes with a NullPointer exception:
09-03 19:37:02.609: E/AndroidRuntime(11325): Caused by: java.lang.NullPointerException
09-03 19:37:02.609: E/AndroidRuntime(11325): at java.lang.StringToReal.parseDouble(StringToReal.java:244)
09-03 19:37:02.609: E/AndroidRuntime(11325): at java.lang.Double.parseDouble(Double.java:295)
09-03 19:37:02.609: E/AndroidRuntime(11325): at williamgill.de.helloworld.Bill.<init>(Bill.java:21)
09-03 19:37:02.609: E/AndroidRuntime(11325): at williamgill.de.helloworld.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:38)
I seem to be doing something obviously wrong with the casting of types - but I can't for the life of me think what.