B
buunguyen
I've got an interesting problem and cannot understand why it happens
this way.
I have a class to encapsulate the set "waiting" cursor.
public class CursorAction {
public CursorAction() {
Cursor currentCursor = getCursor();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
execute();
setCursor(currentCursor);
}
protected void execute(){}
}
I use it as follows:
handleForButtonClick() {
new CursorAction() {
protected void execute() {
server.start();
}
};
}
The above code always throws an exception at the line server.start().
The exception is:
AWT-EventQueue-0Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException
But if I do this then it's always fine:
handleForButtonClick() {
Cursor currentCursor = getCursor();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
server.start();
setCursor(currentCursor);
}
This is really strange because I believe that the 2 code segments do
the same thing. With my understand about threading in Swing/Awt and
anonymous class, I really don't understand why it happens this way.
Anyone has any idea?
this way.
I have a class to encapsulate the set "waiting" cursor.
public class CursorAction {
public CursorAction() {
Cursor currentCursor = getCursor();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
execute();
setCursor(currentCursor);
}
protected void execute(){}
}
I use it as follows:
handleForButtonClick() {
new CursorAction() {
protected void execute() {
server.start();
}
};
}
The above code always throws an exception at the line server.start().
The exception is:
AWT-EventQueue-0Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException
But if I do this then it's always fine:
handleForButtonClick() {
Cursor currentCursor = getCursor();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
server.start();
setCursor(currentCursor);
}
This is really strange because I believe that the 2 code segments do
the same thing. With my understand about threading in Swing/Awt and
anonymous class, I really don't understand why it happens this way.
Anyone has any idea?