aspose file tools*
The moose likes Product and Other Certifications and the fly likes Networking question from Jonathan Knudsen - Beginning J2ME.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Networking question from Jonathan Knudsen - Beginning J2ME.." Watch "Networking question from Jonathan Knudsen - Beginning J2ME.." New topic
Author

Networking question from Jonathan Knudsen - Beginning J2ME..

sab son
Greenhorn

Joined: Apr 26, 2006
Posts: 28
Hi Ranchers,

Need help with Li and Knudsen's 'Begining J2ME , from novice to professional'.

Chapter 10 - Image loader example (page 148).
In order to render the PNG image on the phone, ImageLoader -URL, MIDlet propert has to be modified to a valid PNG image a URL.

I used the URL as in the following code snippet:

public void run() {
HttpConnection hc = null;
DataInputStream in = null;

try {
String url = getAppProperty("http://r0k.us/graphics/images/4kSnake.png");
hc = (HttpConnection)Connector.open(url);
int length = (int)hc.getLength();
byte[] data = null;
if (length != -1) {
data = new byte[length];
in = new DataInputStream(hc.openInputStream());
in.readFully(data);
}...........

As the link given in book is not working. The code compiles with no issues but when I run this on my WTK25 simulator, at run time is complains of illegal argument exception. How do I change the MIDlet property ImageLoader-URL? to render the image on simulator or a real java device?

thanks,
-Sab
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178

String url = getAppProperty("http://r0k.us/graphics/images/4kSnake.png");


sab son,
By looking at the above quote, I guess the property name "http://r0k.us/graphics/images/4kSnake.png" is not available in your application descriptor or Jar manifest.

Using common sense, I guess you want to apply the url directly into the Connector.open method. If so, why don't you just use:

String url = "http://r0k.us/graphics/images/4kSnake.png";


and make the image really accessible from that location?

Hope it helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
sab son
Greenhorn

Joined: Apr 26, 2006
Posts: 28
Ko Ko Man,
thnx for the help, I did change the code to:

String link = "URL http://r0k.us/graphics/images/4kSnake.png";
//String url = getAppProperty("ImageLoader-URL");
hc = (HttpConnection)Connector.open(link);

but now it says 'IllegalargumentException: Invalid Protocol Name'

any suggestion?

previously I did think that my .jad/.jar/.MF files are missing the property,so I did add
'MIDlet-ImageLoader-URL: "http://r0k.us/graphics/images/4kSnake.png" ' in them manually, but nothing happened.

any further suggestions?
sab son
Greenhorn

Joined: Apr 26, 2006
Posts: 28
Ko Ko,

One fellow rancher from j2me forum solved the doubt:

as per Girish Nagaraj:

1. select settings in the KToolbar
2. select user-defined tab & change URL

package application again
1. select project menu option
2. package --> create package
3. copy the jar file from bin folder to the real java device & run

this worked ! thought would be worth to share here.

-Sab.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Yes, sab son. It's good to know that your problem is solved.
 
 
subject: Networking question from Jonathan Knudsen - Beginning J2ME..