1. capndurk's Avatar
    Hi,

    I'm trying to send a small image (PNG or JPG) from my computer to my blackberry simulator via a socket. The entire image seems to transfer fine, the problem arises when I try to display it, by calling:
    Code:
    EncodedImage.createEncodedImage(data, 0, data.length);
    // or
    Bitmap.createBitmapFromBytes(data, 0, -1, 0);
    // or
    Bitmap.createBitmapFromPNG(data, 0, -1);
    I keep getting an IllegalArgumentException error when I call any of these functions with the byte[] that I pass into the constructor of my derived MainScreen class. I don't know what else to do; I've looked up countless other forum posts and used their code to transfer, and it still doesn't work. Here's how I'm connecting to the server:

    SocketConnection sc = (SocketConnection) Connector.open("socket://<my computer's IP>:5000;deviceside=true");
    Please let me know if you guys need any more information. The simulator I'm using is for the BB Storm, and I can copy all the code for both the server and the simulator if needed. I am desperate to find a solution for this.

    Thanks,
    Sean
    07-23-09 02:15 PM
  2. ydaraishy's Avatar
    IllegalArgumentException - If the bytes parameter is invalid, offset or length are invalid.
    Is the bytes parameter valid? Are the offset and length valid?
    07-24-09 04:51 AM
  3. capndurk's Avatar
    Yeah, that's the problem. The bytes parameter is not valid, even though... it is. I'm pretty sure it's receiving all the bytes. I even tried putting the same picture into the IDE and loaded it from the program, and that works. So the picture is guaranteed to be in the correct format. Something must be wrong with the socket. Any ideas?

    Server:
    Code:
    Socket s = ss.accept();
    OutputStream os = s.getOutputStream();
    os.write(data, 0, data.length);
    os.flush();
    Client:
    Code:
    SocketConnection sc = (SocketConnection) Connector.open("socket://<ip>:5000;deviceside=true");
    InputStream is = sc.openInputStream();
    byte[] data = new byte[5000];
    is.read(data, 0, 5000);
    Bitmap b = Bitmap.createBitmapFromBytes(data, 0, data.length, 1);
    add(new BitmapField(b));
    (it fails on createBitmapFromBytes())
    07-24-09 08:22 AM
LINK TO POST COPIED TO CLIPBOARD