You Are Here:

Community: Developer Discussion Boards

#1 Old "bad image format" with signed midlet - 2009-04-25, 06:50

Join Date: Jul 2008
Posts: 6
kvht
Offline
Registered User
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:
byte[] tmp = httpconnectionmanager.getByteArray();
mImage = Image.createImage(tmp,0,tmp.length);
I tested on N73, E63, E71, 5800 XpressMusic.

Can anyone help me to resolve this issue?

Thank inadvance,
Last edited by kvht : 2009-04-25 at 06:57.
Reply With Quote

#2 Old Re: "bad image format" with signed midlet - 2009-04-25, 09:58

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Online
Forum Nokia Champion
When you sign, are you requesting permission for HttpConnection?

Are you sure you're receiving the same byte array in both cases?

Cheers,
Graham.
Reply With Quote

#3 Old Re: "bad image format" with signed midlet - 2009-04-25, 11:39

Join Date: Jul 2008
Posts: 6
kvht
Offline
Registered User
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
Reply With Quote

#4 Old Re: "bad image format" with signed midlet - 2009-04-25, 12:18

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Online
Forum Nokia Champion
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.
Reply With Quote

#5 Old Re: "bad image format" with signed midlet - 2009-04-25, 12:57

Join Date: Jul 2008
Posts: 6
kvht
Offline
Registered User
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);
	}

}
Reply With Quote

#6 Old Re: "bad image format" with signed midlet - 2009-04-25, 13:15

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Online
Forum Nokia Champion
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.
Reply With Quote

#7 Old Re: "bad image format" with signed midlet - 2009-04-26, 05:41

Join Date: Jul 2008
Posts: 6
kvht
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ