×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    11

    disapearing array

    Can anyone help me with a very strange error I am getting? What happens is:

    I read some binary data from an http conection into a byte array and return it:


    int buffLen=2;
    serverData=new byte[buffLen];
    DataInputStream dis=new DataInputStream(is);
    dis.read(serverData,0,buffLen);
    serverData=new byte[ buffLen=(((int)serverData[1])&0xff)|((((int)serverData[0])<<8)&0xff00) ];
    dis.read(serverData,0,buffLen);
    dis.close();
    dis=null;
    is.close();
    is=null;
    conn.close();
    conn=null;
    System.out.println("CONNECTED OK");
    return serverData;

    //note the first 2 bytes are the length of the rest of the data.


    the function returns and the calling function parses the data after printing it. At least it should..

    System.out.println("serverData"+serverData.length);
    for(int i=0;i<serverData.length;i++){
    System.out.println("sd:"+i+":"+serverData[i]);
    }//end for
    System.out.println("DonePrintingServerData");


    this prints the following:

    serverData6042
    sd:0:5
    sd:1:1
    sd:2:64
    sd:3:0
    ...
    sd:1283:-60
    sd:1284:32
    sd:1285:60
    sd:1286:68

    and then it stops..

    the emulator screen says there is a null pointer exception. It never prints "DonePrintingServerData" or even reaches the 6042th

    byte. Just stops there. It also does not print any of the many e.printStackTrace()'s from the try/catch blocks that it is

    wrapped in at different levels, not even the one in the run() method inside of which all function calls originate. Which is to

    bad because I also have it set up to display a message on the actual phone, and prevent a complete app crash should any of those

    catch blocks catch anything. (with this bug it doesnt seem to matter)

    If I comment out the printing section it works fine on the EMULATOR and parses everything perfectly. It parses ALL of the data

    that is comming in from my servlet, and it does it correctly.

    So as wierd as that seems, I try running it on an actual phone after removing the System.out.println()'s and that print loop. I

    get the same null pointer error at the same point in execution. I can tell that it is in that point of execution because of were

    the app is when it crashes, not because of any thing I get back, because all i get back is the white default null pointer

    exception screen.

    I am at a loss here. There are no other threads working in my app. It doesnt matter if I make the byte array a static data

    member of the class, or if I return it, or even if I make a byte[][] serverData=new byte[1][] and pass it into the http request

    function and assign the data to serverData[0]=byteArrayData; to bypass how java passes references by value to return it through

    a function paramater. But its as if the array is garbage collected when it shouldnt be or something. The only things refrenced

    in that loop is the serverData[] and System.out. How could this happen?

    One of our other programmers thinks that the array is not totaly inintialized, but its a byte array, not an object array. I dont

    know, if any one has any ideas I would greatly appreciate hearing from you.


    oh, btw, this is the second time this function executes when this happens. It uses the same function to parse all server data regardless of the request/response. The first time it works perfectly on both the phone and the emulator. It is the second time that the phone accesses the web that it crashes like this. Dont know if that helps.




    oh, one other thing:

    I tried:

    System.out.println("serverData"+serverData.length);
    for(int i=serverData.length-1;i>0;i--){
    //System.out.println("sd:"+i+":"+serverData[i]);
    serverData[i]=serverData[i];
    for(int j=0;j<1000;j++);
    }//end for
    System.out.println("DonePrintingServerData");

    just to verify that the System.out object want it.. It prints:


    serverData7143

    then crashes with the same error. So either the array disapears into thin air, or its some thread in the vm, cause I dont have any other threads.
    Last edited by skarsten; 2005-02-12 at 03:05.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×