04-13-2010 01:15 PM
I recently got interested in programming again and decided to start out with blackberry programming. I am getting some errors right off the bat which is not encouraging but I was hoping someone could help me out.
I created a basic app based on the "Getting Started" first app tutorial. I added then added a button and a field listener for that button which displays a dialog alert. Very simple, but in my simulator (9550) I am getting a runtime exception that stops at 'TouchEventInternal.getGlobalX(int)'. This happens after I click 'OK' on the dialog alert.
Here is the Stack Trace:
Thread [Checklist(176)id=295857152] (Suspended (exception RuntimeException)) TouchEventInternal.getGlobalX(int) line: 222 ChecklistScreen(Screen).dispatchTouchEvent(TouchEvent) line: 1010 UiEngineImpl.processMessage(Object, Message, boolean) line: 3388 Checklist(Application).doProcessNextMessage(Messag e) line: 2268 Checklist(Application).processNextMessage(Message) line: 1530 Checklist(Application).enterEventDispatcher() line: 1371 Checklist.main(String[]) line: 11
And Here is my Code:
CheckList.java:
package com.rim.samples.checklist;
import net.rim.device.api.ui.UiApplication;
public class Checklist extends UiApplication
{
public static void main(String[] args)
{
Checklist theApp = new Checklist();
theApp.enterEventDispatcher();
}
public Checklist()
{
pushScreen(new ChecklistScreen());
}
}
ChecklistScreen.java:
package com.rim.samples.checklist;
import java.util.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.*;
public final class ChecklistScreen extends MainScreen
{
public ChecklistScreen()
{
super();
ButtonField button = new ButtonField("Add New");
FieldChangeListener action = new FieldChangeListener(){
public void fieldChanged(Field field, int context)
{
Dialog.alert("YOU PUSHED A BUTTON");
}
};
button.setChangeListener(action);
add(button);
}
public boolean onClose()
{
Dialog.alert("Cya!");
System.exit(0);
return true;
}
}
Any help or guidance would be appreciated
Solved! Go to Solution.
04-14-2010 03:55 AM - edited 04-14-2010 03:58 AM
Hey Micah_H!
I guess that you need access to the UI event-handling, since it seems that you are outside. So, you can use the invokeLater( ) or invokeAndWait( ) methods.
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
Dialog.alert("YOU PUSHED A BUTTON");
}
});
The other alternative is to set the CONSUME_CLICK feature at your button:
ButtonField button = new ButtonField("Add New", ButtonField.CONSUME_CLICK);
Anyway, honestly, I got surprised when your code works on previous simulator 9530. I do not know why!
Regards,
Klerisson
04-14-2010 12:00 PM
Adding CONSUME_CLICK to my button caused the error to go away. Hopefully there are no side effects to using this flag.
Thank you.