I have a class called HtmlConnect.java. I declare the variable log as follows:
public Log log = Log.getInstance();
The Log.java file looks like this:
public class Log {
private static Log instance = null;
private String log;
private Log() {
}
public static Log getInstance() {
if (instance == null) {
instance = new Log();
}
return instance;
}
public String getLog() {
return log;
}
public void appendLog(String message) {
this.log.concat(message+"\n");
}
}
So when I call
log.appendLog("TestLog");
I always get a nullpointer exception. Why is taht?
appendLogwithout first have instantiate thelog.this.log.concat(message+"\n");returns the result. Discarding the result won't do anything.