Hi Guys,
I think I have a synchronization problem...It may be too basic..Please help..
I have a thread the run method of which is below
public void run()
{
while(true)
{
try {
for (int i = 0; i < 100; i++) {
buf.append(hello + (myint++));
}
buf.append("\n");
adapter.setData(buf.toString());
buf = null;
buf = new StringBuffer();
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(TestThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
I am creating new string data in each run and passing it to the adapter class setData method..
In the adapter class my setData is like this..
public boolean setData(String sb){
str = sb;
if(str != null && !str.equalsIgnoreCase("")){
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
System.out.println("inside run.....");
System.out.println("str length:- "+str.length());
//do sth after this..
}
}
But once in a while I get null pointer exception at the line str.length()...I get this even when I try to create a new string with the buf.toString() in the first run method..
What am I doing wrong??
Thanks in advance..