12-16-2008 06:02 PM
I am new to Blackberry/Java development and am having some issues connecting to a .net webservice using ksoap2. The application basically connects to the webservice, gets a list of items, populates a vetor and returns that vector to populate a listfield. I can get this to work on the very first screen of the application, but when the user clicks on one of the list items, and goes to the next screen, the listfield does not get populated and just displays an empty message. The application works perfectly on the simulator, but as soon as I load it into my phone (Sprint 8830), it only populates the first listfield. I am not sure what I am doing wrong. Any help would be greatly appreciated.
--WWTracker.java code--
public class WWTracker extends UiApplication { public static void main(String[] args) { WWTracker theApp = new WWTracker(); theApp.enterEventDispatcher(); } public WWTracker() { pushScreen(new WWTrackerScreen()); } } final class WWTrackerScreen extends MainScreen { private ListField myList; private ListCallback myCallback; private WWTrackerScreen2 _wwTrackerScreen2; private class ListCallback implements ListFieldCallback { private Vector listElements = new Vector(); public void drawListRow(ListField list, Graphics g, int index, int y, int w) { String text = (String)listElements.elementAt(index); g.drawText(text, 0, y, 0, w); } public Object get(ListField list, int index) { return listElements.elementAt(index); } public int indexOfList(ListField list, String p, int s) { return listElements.indexOf(p, s); } public int getPreferredWidth(ListField list) { return Graphics.getScreenWidth(); } public void insert(String toInsert, int index) { listElements.addElement(toInsert); } public void erase() { listElements.removeAllElements(); } } public WWTrackerScreen() { super(); setTitle(new LabelField("Call Purpos-YESS", LabelField.ELLIPSIS | LabelField.FIELD_HCENTER)); GetListThread mt = new GetListThread(); Vector lvm = new Vector(); lvm = mt.GetList(); myList = new ListField(); myCallback = new ListCallback(); myList.setCallback(myCallback); for (int c=0; c < lvm.size(); c++) { myList.insert(c); myCallback.insert(lvm.elementAt(c).toString(), c); } add(myList); } public boolean onClose() { System.exit(0); return true; } public boolean onEnter() { int myIndex = myList.getSelectedIndex(); String mySelection = String.valueOf(myCallback.get(myList, myIndex)); Dialog.alert("You chose: " + mySelection);// + " - " + mt.GetUser()); _wwTrackerScreen2 = new WWTrackerScreen2(); Ui.getUiEngine().pushScreen(_wwTrackerScreen2); return true; } public boolean keyChar(char key, int status, int time) { boolean retval = false; switch (key) { case Characters.ESCAPE: onClose(); retval = true; break; case Characters.ENTER: onEnter(); retval = true; break; } return retval; } protected boolean trackwheelClick(int status, int time) { onEnter(); return true; } private class WWTrackerScreen2 extends MainScreen { private ListField myList; private ListCallback myCallback; private class ListCallback implements ListFieldCallback { private Vector listElements = new Vector(); public void drawListRow(ListField list, Graphics g, int index, int y, int w) { String text = (String)listElements.elementAt(index); g.drawText(text, 0, y, 0, w); } public Object get(ListField list, int index) { return listElements.elementAt(index); } public int indexOfList(ListField list, String p, int s) { return listElements.indexOf(p, s); } public int getPreferredWidth(ListField list) { return Graphics.getScreenWidth(); } public void insert(String toInsert, int index) { listElements.addElement(toInsert); } public void erase() { listElements.removeAllElements(); } } public WWTrackerScreen2() { super(); setTitle(new LabelField("Contact List", LabelField.ELLIPSIS | LabelField.FIELD_HCENTER)); GetListThread mt = new GetListThread(); Vector lvm = new Vector(); lvm = mt.GetList(); myList = new ListField(); myCallback = new ListCallback(); myList.setCallback(myCallback); for (int c=0; c < lvm.size(); c++) { myList.insert(c); myCallback.insert(lvm.elementAt(c).toString(), c); } add(myList); } public boolean onClose() { System.exit(0); return true; } public boolean onEnter() { int myIndex = myList.getSelectedIndex(); String mySelection = String.valueOf(myCallback.get(myList, myIndex)); Dialog.alert("You chose: " + mySelection ); return true; } public boolean keyChar(char key, int status, int time) { boolean retval = false; switch (key) { case Characters.ESCAPE: //onClose(); Ui.getUiEngine().pushScreen(new WWTrackerScreen()); retval = true; break; case Characters.ENTER: onEnter(); retval = true; break; } return retval; } protected boolean trackwheelClick(int status, int time) { onEnter(); return true; } } private class AccountIDScreen extends MainScreen { private TextBoxField tbf; public AccountIDScreen() { setTitle(new LabelField("Account Registration", LabelField.ELLIPSIS | LabelField.FIELD_HCENTER)); LabelField lblAcct = new LabelField("Enter Your AccountID:"); add(lblAcct); tbf = new TextBoxField(300,20); add(tbf); } public boolean onEnter() { VerifyUserThread dt = new VerifyUserThread(); boolean blResult = dt.VerifyUser(tbf.getText()); if (blResult == true) { Ui.getUiEngine().pushScreen(new WWTrackerScreen()); } else { Dialog.alert("Invalid Account ID! Please Try Again. '" + tbf.getText() + "'"); } return true; } protected boolean trackwheelClick(int status, int time) { onEnter(); return true; } } }
--GetContactListThread.java code--
public class GetContactListThread extends Thread { public Vector GetContactList() { SoapObject rpc = new SoapObject("http://www.****.net/", "sendContactList"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.encodingStyle = SoapSerializationEnvelope.XSD; HttpTransport ht = new HttpTransport("http://www.****.net/Tracker/ACTrack.asmx"); ht.debug = true; Vector vim = new Vector(); try { ht.call("http://www.****.net/sendContactList", envelope); vim = (Vector) envelope.getResponse(); } catch (org.xmlpull.v1.XmlPullParserException ex2) { //return ex2.toString(); } catch (Exception ex) { //return "ex: " + ex.toString(); } return vim; } }
--GetListThread.java code--
public class GetListThread extends Thread { public Vector GetList() { SoapObject rpc = new SoapObject("http://www.****.net/", "sendList"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.encodingStyle = SoapSerializationEnvelope.XSD; HttpTransport ht = new HttpTransport("http://www.****.net/Tracker/ACTrack.asmx"); ht.debug = true; //String result = ""; Vector vim = new Vector(); try { ht.call("http://www.****.net/sendList", envelope); //result = (envelope.getResponse()).toString(); vim = (Vector) envelope.getResponse(); //result = vim.elementAt(1).toString(); } catch (org.xmlpull.v1.XmlPullParserException ex2) { //return ex2.toString(); } catch (Exception ex) { //return "ex: " + ex.toString(); } return vim; } }
12-18-2008 02:57 PM
12-18-2008 04:55 PM
Hi Mark,
Thank you for your reply. I did what you said and was able to get an error. The error is "java.lang.RuntimeException: blocking operation not permitted on event dispatch thread". I am not sure what this means. The application is calling two different threads, so they should not be blocking each other, I assume. Why is it that I don't get this error on the simulator? I really appreciate all of your help.
Luis
12-23-2008 09:30 AM
The link below describes this error. The BlackBerry Simulator does not force all instances of this (mainly those that involve network connections since its firewall is disabled).
What Is - Blocking operation not permitted on event dispatch thread
Article Number: DB-00521