JavaME MIDlet will not clear variables?

I wrote a JavaME program that calls a web service to get the values, the web service runs on a tomcat server.

I ran into a very strange problem: whenever I run the program, the program loads the new values ​​as I expected, but instead of adding them to the unified array, it seems to save the previous values ​​of the arrays and just add them. Perhaps the code will better explain this.

First, I create a string array to store the extracted values ​​and a small int value that will be used when passing through them, I also create a repository for services and stubs:

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

The midlet then calls the form when the startApp () method is launched, and this allows you to enter a value in the text box, and then press the send command to send the value to the server, this server will send an array of values ​​(More precisely, 18). To implement this, I call the commandAction () method.

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 load and put 18 values ​​into the string array and loop through them. He does this, but he will not discard previous values ​​from the array for reasons that I cannot understand.

, , , 18 , 18 , 18 , . IDE, Netbeans, - , 0 .

15- , :

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

- , ?

+3
1

getDataService_Stub.getStock. , . , .

0

Source: https://habr.com/ru/post/1784827/


All Articles