Respected Friends, I am trying to establish HTTP connection through my J2ME application and trying to read the contents of a web page using this HTTP connection,but the code is throwing exceptions,I got this code from the book "Wireless Java Programming with Java 2 Micro Edition" by Yu Feng and Jun Zhu,according to the author the code is running fine and the author has also shown the results in his book,can any one please tellwhy is it throwing exceptions on my PC,the code is as follows:
Please reply as soon as possible.
Thanking You, Salman Faraz. [ July 17, 2005: Message edited by: Mark Spritzler ]
Respected Friend, If I change the address to www.javaranch.com or www.yahoo.com than also the same exception is thrown,which means that either the toolkit fails to establish a connection or if it establishes a connection it fails to read the contents of the web page,can you please tell me thereason behind this?if there is some error in the code than please corrent it and inform me.
Thanking You, Salman Faraz.
Glenn Castro
Ranch Hand
Joined: Aug 24, 2003
Posts: 78
posted
0
When I run your code, I encountered the following warning:
Running with storage root DefaultColorPhone Warning: To avoid potential deadlock, operations that may block, such as networking, should be performed in a different thread than the commandAction() handler.
Glenn Castro<br />Sun Certified Web Component Developer
lexander Bosco
Ranch Hand
Joined: Feb 21, 2005
Posts: 65
posted
0
hi salman
i have used the same book too though haven't tried out that particular example but with some related experience i will advise u to use tomcat or any other servlet container on ur system or a system on ur local network to try it out so u will just change the address to .http://localhost:8080/app/mypage.html or whatever try this i blieve it will work.
lets here what happens afterwards. yeah castro the command handler() thing i get also but i think it due t when u tryin to make a connection it cant establish from ur machine
[ July 28, 2005: Message edited by: lexander Bosco ] [ July 28, 2005: Message edited by: lexander Bosco ]
there is no knowledge that is not power<br />-<br />SCJP 1.4<br />SCWCD in progress<br />SCMAD in progress
Originally posted by Glenn Castro: When I run your code, I encountered the following warning:
Running with storage root DefaultColorPhone Warning: To avoid potential deadlock, operations that may block, such as networking, should be performed in a different thread than the commandAction() handler.
Actually that statement is just a warning and not a problem, it is merely a suggestion to create a new thread. But in many applications you want it to block.
Warning: To avoid potential deadlock, operations that may block, such as networking, should be performed in a different thread than the commandAction() handler.
the problem is caused as you have performed an io or http action in the command handler. do as it says make it a different thread.try this code out
this code goes inside your command handler new Thread(new Runnable() { public void run() { try{ //your desired action }catch(Exception e){} } } ).start();