J
Jeff
Hey
midp 2.0
J2ME Wireless Toolkit 2.2
JDK 5
I get an NullPointerException when running the code (copy of code added
below, data output also added under the code), and I don't know what is
causing this exception... If you see what I'm doing wrong here, then please
tell me
public void checkKeys() {
int keyState = getKeyStates();
System.out.println(keyState);
if ((keyState & LEFT_PRESSED) != 0) {
System.out.println("LEFT_PRESSED");
}
}
***************************
Here is the thread code, you see that checkKeys are called in the loop
public void run() {
testCanvas.flushKeys();
testPause = false;
testStop = false;
while (true) {
if (testStop) {
break;
}
while (testPause) {
synchronized(this) {
try {
wait();
}
catch (Exception e) {
}
}
synchronized(this) {
try {
wait(1);
}
catch(Exception e) {}
}
}
testCanvas.checkKeys();
testCanvas.advance();
}
}
The output from this code is (as you can see from the output that this
output contain data from more than one iteraton):
I did click only 1 time on LEFT_PRESSED (on emulator) and it looks like the
loop are processing my click several times (getKeyStates= 4, 4, 0, 0):
4
LEFT_PRESSED
java.lang.NullPointerException
4
LEFT_PRESSED
java.lang.NullPointerException
0
0
0
-1
LEFT_PRESSED
java.lang.NullPointerException
-1
LEFT_PRESSED
java.lang.NullPointerException
-1
LEFT_PRESSED
java.lang.NullPointerException
I'm very thankful for help on this issue!
Jeff
midp 2.0
J2ME Wireless Toolkit 2.2
JDK 5
I get an NullPointerException when running the code (copy of code added
below, data output also added under the code), and I don't know what is
causing this exception... If you see what I'm doing wrong here, then please
tell me
public void checkKeys() {
int keyState = getKeyStates();
System.out.println(keyState);
if ((keyState & LEFT_PRESSED) != 0) {
System.out.println("LEFT_PRESSED");
}
}
***************************
Here is the thread code, you see that checkKeys are called in the loop
public void run() {
testCanvas.flushKeys();
testPause = false;
testStop = false;
while (true) {
if (testStop) {
break;
}
while (testPause) {
synchronized(this) {
try {
wait();
}
catch (Exception e) {
}
}
synchronized(this) {
try {
wait(1);
}
catch(Exception e) {}
}
}
testCanvas.checkKeys();
testCanvas.advance();
}
}
The output from this code is (as you can see from the output that this
output contain data from more than one iteraton):
I did click only 1 time on LEFT_PRESSED (on emulator) and it looks like the
loop are processing my click several times (getKeyStates= 4, 4, 0, 0):
4
LEFT_PRESSED
java.lang.NullPointerException
4
LEFT_PRESSED
java.lang.NullPointerException
0
0
0
-1
LEFT_PRESSED
java.lang.NullPointerException
-1
LEFT_PRESSED
java.lang.NullPointerException
-1
LEFT_PRESSED
java.lang.NullPointerException
I'm very thankful for help on this issue!
Jeff