Sukhada
Sukhada

Reputation:

Why am I getting an IllegalArgumentException with this code to create an image?

I wrote this code for my j2me project:

try {
    Image immutableThumb = Image.createImage(temp, 0, temp.length);
} catch (Exception ex) {
    System.out.println(ex);
}

Where temp is a byte array.

When I tried it for localhost it works, and the image gets created. But when I tried it on LAN it throws an IllegalArgumentException, and the image is not created.

How can I solve this problem?

Upvotes: 0

Views: 258

Answers (3)

sfish
sfish

Reputation: 422

Is it on device or in emulator that you are having a problem? It could be the url string, or a problem with the connection.

Can you post all your source code?

Here's a simple example: how to download an image from a web-server.

Upvotes: 0

Stefano Driussi
Stefano Driussi

Reputation: 2261

If you get the byte array from a network location, be sure it came from a supported image type. I mean, not every image format is available on MIDP. To be sure, you can use PNG.

Upvotes: 0

Stephen Denne
Stephen Denne

Reputation: 37027

The docs say

IllegalArgumentException - if imageData is incorrectly formatted or otherwise cannot be decoded

so I'd say you're getting a different byte array.

Upvotes: 2

Related Questions