Help with null pointer exception...

Hi,

I don't know why but i'm getting a null pointer exception when i call this method.

/**

* To String method

*/

public String toString()

{

String returnString;

returnString =" House ID : "+ id +"\n House address : " + address +"\n Date Built : " + df.format(dateBuilt) +"\n Selling price : " + nf.format(sellingPrice)

+"\n Sold : " + isSold +"\n";

if(soldDate!=null){

returnString +=" Date of sale : "+ df.format(soldDate);

}

return returnString;

}

My instance variables are as follows..

private String id;

private String address;

private double sellingPrice;

public boolean isSold;

private Date dateBuilt;

private Date soldDate;

private Buyer buyer;

private boolean yearDifference;

private DateFormat df;

private double stampDuty;

private NumberFormat nf;

Can anyone help me? Thanks

[1409 byte] By [Capsuda] at [2007-11-27 3:42:21]
# 1
Post the stack trace.It could be df is null or nf is null or...
jbisha at 2007-7-12 8:45:56 > top of Java-index,Java Essentials,Java Programming...
# 2
Sorry...but whats the stack trace?
Capsuda at 2007-7-12 8:45:56 > top of Java-index,Java Essentials,Java Programming...
# 3
Ok i fixed it...silly me. Thanks anyway
Capsuda at 2007-7-12 8:45:56 > top of Java-index,Java Essentials,Java Programming...
# 4

The stack trace is the information that prints along with the exception that shows the various methods that the program was in.

It can also be programmatically displayed by calling Exception.PrintStackTrace(). The stack trace is one of the easiest ways to see were an exception actually occurred.

Example:

public class Test114 {

public static void main(String[] args) {

Object o = null;

methodOne(o);

}

public static void methodOne(Object o) {

methodTwo(o);

}

public static void methodTwo(Object o) {

System.out.println(o.toString());

}

}

+javac Test114.java

+java Test114

Exception in thread "main" java.lang.NullPointerException

at Test114.methodTwo(Test114.java:10)

at Test114.methodOne(Test114.java:7)

at Test114.main(Test114.java:4)

+

Message was edited by:

jbish

jbisha at 2007-7-12 8:45:56 > top of Java-index,Java Essentials,Java Programming...