Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

when i run a swing multi threaded application i got the following exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException.

I'm posting the sample code below:

publicsynchronizedvoid executeCommand(String directoryPath){

Runnable runnable =null;

Thread taskThread =new TaskThread(runnable,directoryPath);

taskThread.start();

}

[code]

public class TaskThread extends Thread {

private Runnable updateUIRunnable;

public TaskThread( Runnable aRunnable,String directoryPath) {

updateUIRunnable = aRunnable;

this.directoryPath=directoryPath;

}

public void run() {

//doTask();

try {

semaphore.acquire();

executeCommand();

}

catch(InterruptedException e) {

System.out.println(e.getMessage());

}

finally {

semaphore.release();

}

SwingUtilities.invokeLater( updateUIRunnable );

}

public void executeCommand() {

// some task

}

}

Can any one suggest me a way to fix this exception.

Thanks

[1342 byte] By [muralikrishna_mka] at [2007-10-3 3:15:40]
# 1

when i run a swing multi threaded application i got the following exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException.

I'm posting the sample code below:

public synchronized void executeCommand(String directoryPath) {

Runnable runnable = null;

Thread taskThread = new TaskThread(runnable,directoryPath);

taskThread.start();

}

public class TaskThread extends Thread {

private Runnable updateUIRunnable;

public TaskThread( Runnable aRunnable,String directoryPath) {

updateUIRunnable = aRunnable;

this.directoryPath=directoryPath;

}

public void run() {

//doTask();

try {

semaphore.acquire();

executeCommand();

}

catch(InterruptedException e) {

System.out.println(e.getMessage());

}

finally {

semaphore.release();

}

SwingUtilities.invokeLater( updateUIRunnable );

}

public void executeCommand() {

// some task

}

}

Can any one suggest me a way to fix this exception.

Thanks

muralikrishna_mka at 2007-7-14 21:07:01 > top of Java-index,Java Essentials,Java Programming...
# 2
You pass a Runnable which is null: Runnable runnable = null;
PhHeina at 2007-7-14 21:07:01 > top of Java-index,Java Essentials,Java Programming...
# 3

Runnable runnable = null;

Thread taskThread = new TaskThread(runnable,directoryPath);

taskThread.start();

public TaskThread( Runnable aRunnable,String directoryPath) {

updateUIRunnable = aRunnable;

Dont you see anything wrong with this snippet of code?

updateUIRunnable = null;

Runnable is an interface which provides only one abstract method

public void run()

When using multithreading in a program,if you are going to implement only run() method, it is wise to implement Runnable instead of Thread. You extend Thread to use or override some of it's methods, and since you are not doing any of this i really dont see the gain here.

Andreas.CYa at 2007-7-14 21:07:01 > top of Java-index,Java Essentials,Java Programming...