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
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
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.