BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-20-2008, 07:06 PM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8830
PIN: N/A
Carrier: Sprint
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie Help

Please Login to Remove!

Hello All,

I am new to BB development. I come from a C# background and am having a heck of a time learning J2ME. I am developing an app that connects to my .net webservice using ksoap2. I have no issues with that part, I can communicate fine with the webservice if it is just one screen. The issue I have is that when I navigate from the first screen to the second screen, my list does not get populated by the webservice. I'm thinking that it might be a threading issue, but since this is all new to me I don't know. Please see my code below. Any help would be greatly appreciated. Also, the code below works fine in the emulator, but ceases to work when I install it on my 8830. Thanks.

Tracker.java code:
Code:
public class Tracker extends UiApplication
{
    public static void main(String[] args)
    {
        Tracker theApp = new Tracker();
        theApp.enterEventDispatcher();
    }

    public Tracker()
    {
        pushScreen(new TrackerScreen());
    }
    
}



final class TrackerScreen 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 TrackerScreen()
    {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        setTitle(new LabelField("Call Purpose", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));        
        
        DataThread mt = new DataThread();       
        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());  
            Ui.getUiEngine().pushScreen(new TrackerScreen2());            

        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;
    }
}


class TrackerScreen2 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 TrackerScreen2()
    {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        setTitle(new LabelField("Contact List", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));        
        
        DataThread mt = new DataThread();
        Vector lvm = new Vector();
        lvm = mt.GetContactList();
        
        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();
            retval = true;
            break;
        case Characters.ENTER:
            onEnter();
            retval = true;
            break;
        }

        return retval;
    }
}






DataThread.java code:

Code:
class DataThread extends Thread{
    DataThread() {    }
    
        public String GetUser() {
            SoapObject rpc = new SoapObject("####", "HelloWorld");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.bodyOut = rpc;
            envelope.dotNet = true;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            
            HttpTransport ht = new HttpTransport("####/ACTrack.asmx");
            ht.debug = true;
            
            try{
                ht.call("####/HelloWorld", envelope);
                
                String result = (envelope.getResponse()).toString();
                
                return "result: " + result;
            }
            catch (org.xmlpull.v1.XmlPullParserException ex2){
                return ex2.toString();
            }
            catch (Exception ex){
                return "ex: " + ex.toString();
            }
        } 
        
        public String SetUser(String strUser){        
          
            SoapObject myObject = new SoapObject("####", "GimmeData");
            myObject.addProperty("data", strUser);
            
            SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            env.bodyOut = myObject;
            env.dotNet = true;
            env.encodingStyle = SoapSerializationEnvelope.XSD;

            HttpTransport ht = new HttpTransport("####/ACTrack.asmx");
            ht.debug = true;

            //env.setOutputSoapObject(myObject);
            
            try{
                ht.call("####/GimmeData",env);
                String result = (env.getResponse()).toString();
                return result;
            }
            catch (Exception ex){
                return ex.toString();
            }            
        }

        public Vector GetList() {
            SoapObject rpc = new SoapObject("####", "sendList");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.bodyOut = rpc;
            envelope.dotNet = true;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            
            HttpTransport ht = new HttpTransport("####/ACTrack.asmx");
            ht.debug = true;
            
            String result = "";
            Vector vim = new Vector();            
            try{
                ht.call("####/sendList", envelope);
                                
                vim = (Vector) envelope.getResponse();
            }
            catch (org.xmlpull.v1.XmlPullParserException ex2){
                //return null;
            }
            catch (Exception ex){
                //return null;
            }           
            
            return vim;
        } 

        public Vector GetContactList() {
            SoapObject rpc = new SoapObject("####", "sendContactList");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.bodyOut = rpc;
            envelope.dotNet = true;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            
            HttpTransport ht = new HttpTransport("####/ACTrack.asmx");
            ht.debug = true;
            
            String result = "";
            Vector vim = new Vector();            
            try{
                ht.call("####/sendContactList", envelope);
                                
                //result = (envelope.getResponse()).toString();
                vim = (Vector) envelope.getResponse();
                //result = vim.elementAt(1).toString();
            }
            catch (org.xmlpull.v1.XmlPullParserException ex2){
                //return null;
            }
            catch (Exception ex){
                //return null;
            }           
            
            return vim;
        } 
   
}

Last edited by jdmjza80 : 11-21-2008 at 01:05 PM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.