Hi all,
in the code below i download the png file 'testje.png'. This all goes well. But then i want to create an image from the bytearray i downloaded. I get an 'IllegalArgumentException' on:
m_Img = Image.createImage(img, 0, img.length);
**************
package com.notthefly.mobile.Roel_GPRS;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class Roel_GPRS extends MIDlet {
HttpConnection m_Con = null;
InputStream m_Is = null;
Display m_Display = null;
String m_Url = "http://www.solidweb.nl:80/stage/testje.png";
Image m_Img = null;
int i = 0;
int nBYTES = 60000;
public Roel_GPRS(){
m_Display = Display.getDisplay(this);
}
public void startApp() {
m_Tb = new TextBox("TestMIDlet", "Opening conn...\n", 1024, 0);
m_Display.setCurrent(m_Tb);
try{
// Open http connection.
m_Con = (HttpConnection)Connector.open(m_Url);
/*
int response = m_Con.getResponseCode();
System.out.println("RESP: " + response);
if (response == 200) {
m_Tb = new TextBox("TestMIDlet", "Connection opened...\n", 1024, 0);
m_Display.setCurrent(m_Tb);
}*/
// Open inputstream
m_Is = m_Con.openInputStream();
int length=(int) m_Con.getLength();
int ch;
int teller = 0;
byte image[] = new byte[nBYTES];
while ((ch = m_Is.read()) != -1) {
image[count++] = (byte) ch;
}
byte img[] = new byte[count];
for (int i = 0; i < count; i++) {
img[i] = image[i];
}
m_Img = Image.createImage(img, 0, img.length);
}
catch(IOException e){
System.out.println("TEST");
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
********
I hope for an answer that solves my problem,
thanks in advance!
EDIT: i think i'd better placed this topic in the 'java' forum instead of 'networking'.

Reply With Quote

