| Reply | « Previous Thread | Next Thread » |
|
Hi,
I have had a problem with signed midlet below: -with unsign midlet, app can view image from HttpConnection -when I sign this midlet, "bad image format" exception throw out The image is JPG format. Quote:
Can anyone help me to resolve this issue? Thank inadvance,
Last edited by kvht : 2009-04-25 at 06:57.
|
|
When you sign, are you requesting permission for HttpConnection?
Are you sure you're receiving the same byte array in both cases? Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Yes, midlet has HttpConnection permission.
I used only build with sign and unsign to test. This error occur with creation image, I can get text data. I also check the size of byte array, there're no difference between these builds. thanks, kvht |
|
What if you put the jpeg file in the JAR? Try loading it from the JAR using createImage(filename), and by using getResourceAsStream(), then creating from the byte[]. (Rationale: work isolate the problem as HttpConnection or createImage.)
Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Hi Graham,
This is code that I tested. It OK! Code:
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {
public MainMidlet() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Form frm = new Form("Test");
try {
Image img = Image.createImage("/i.jpg");
frm.append(img);
} catch (Exception e) {
frm.append((new StringBuffer("Err: ")).append(e.getMessage()).toString());
}
try {
Image img = Image.createImage((new String("")).getClass().getResourceAsStream("/i.jpg"));
frm.append(img);
} catch (Exception e) {
frm.append((new StringBuffer("Err: ")).append(e.getMessage()).toString());
}
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream is = (new String("")).getClass().getResourceAsStream("/i.jpg");
int _int;
while ((_int = is.read())!=-1){
bos.write(_int);
}
byte[] tmp = bos.toByteArray();
Image img = Image.createImage(tmp,0,tmp.length);
frm.append(img);
} catch (Exception e) {
frm.append((new StringBuffer("Err: ")).append(e.getMessage()).toString());
}
Display.getDisplay(this).setCurrent(frm);
}
}
|
|
You get all three images? Even if you sign the MIDlet?
OK... I still have no idea why it doesn't work!! :-) My next suggestion is: put the jpeg in the JAR, and download it from the server. Load the jpeg from the JAR into a byte[], so you can compare the JAR byte[] with the HTTP-downloaded byte[]. If you have two identical byte[]'s, then either both must work, or both must fail. If they are different... then something strange is happening in the HttpConnection. Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Thank you, Graham.
I found out why it did not work. With signed build, HttpConnection does set (or set wrong +_+) User-Agent so server return an error. It will be resolved by fixing on server or set an User-Agent (any :D) on client. -kvht |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| --- ???save image problem??? --- | ferenn | Mobile Java Media (Graphics & Sounds) | 6 | 2007-10-01 15:33 |
| Opening a JPEG Image | ummarbhutta | Mobile Java Media (Graphics & Sounds) | 8 | 2007-02-15 07:34 |
| DRM FL + Signed midlet not installing | amvyas82 | Mobile Java General | 4 | 2006-07-28 22:02 |
| Beta Tester Needed for Image protection midlet (FileConnection API) | thongtom | Mobile Java General | 0 | 2005-09-13 11:10 |
| Successfully Signed A Midlet but Bluetooth connection failed | ManiDCI | Mobile Java General | 0 | 2005-02-16 19:17 |