NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

JavaME MIDlet Will Not Clear and Reset Variables?

 
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users
View previous topic :: View next topic  
Author Message
pike168



Joined: 11 Jan 2011
Posts: 1

PostPosted: Tue Jan 11, 2011 10:09 pm    Post subject: JavaME MIDlet Will Not Clear and Reset Variables? Reply with quote

I have written a JavaME program that accesses a web service to retrieve values, the web service is running on a tomcat server. I am facing a very strange problem, whenever i run the program, the program downloads new values like i anticipated but instead of adding them to an unitialied array it seems to store the previous arrays values and just add them. Maybe the code would explain it better.

I first create a string array to store the retrieved values and a small int value to use when looping through them, i also create storage for the services and stubs:
Code:

    public class StockQuery extends MIDlet implements CommandListener
    {
        String[] newResults = null;
        int i = 0;
        String stockSym = null;
        getDataService service = null;
        .....
   

The midlet then calls a form when the startApp() method runs and this lets to the input a value into a textbox and then press the send command to send the value to a server, this server will send back an array of values (18 to be precise). To implement this i then call the commandAction() method.
Code:

    public void commandAction(Command c, Displayable d)
    {
        else if(c == cmdSend)
        {
            stockSym = getSym.getString();
            service = new getDataService_Stub();
            try
            {
                newResults = service.getStock(stockSym);
                for(i=0; i<newResults.length; i++)
                {
                    System.out.println("Data " + i + "    -    " + newResults[i]);
                }
            }
            catch (RemoteException ex)
            {
                ex.printStackTrace();
            }
 

Now the program should download and place 18 values into the string array and the loop through them. It does do this but it will not flush the previous values from the array for reasons i cant quite figure out.

For example, the first time i executed the loop, the program did loop and print the 18 values, however the second time, it printed the initial 18 values from the previous run and then the extra 18 values it had just downloaded. I have closed my IDE, restarted my PC and deleted netbeans cache folder and for some reason it will always store the values in the string array and the loop value even though i declared it to 0 whenever the program starts.

I am now on my 15th run of the program and the program output is:
Code:

     Data 267    -    34092040
     Data 268    -    22.73 - 31.58
     Data 269    -    NasdaqNM
     Data 270    -    1.95
     

Can anyone explain why the variables are not being cleared even after exiting and restarting netbeans and even after clearing the netbeans cache?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo