• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

problem with HTTP connection in J2ME

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The address is not found.

Just putting the address in a web browser comes back with a "404 Not FOund"

Mark
 
Salman Faraz
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

So I tried to change some code and make it run the connection in a separate thread. The address, http://64.28.105.110/servlets/webyu/Chapter7Servlet?request=gettimestamp, returns 404 Not Found. But if I tried to change the address into http://www.google.com it runs fine.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

So I tried to change some code and make it run the connection in a separate thread. The address, http://64.28.105.110/servlets/webyu/Chapter7Servlet?request=gettimestamp, returns 404 Not Found. But if I tried to change the address into http://www.google.com it runs fine.



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.

Mark
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code works fine for me too. Using www.google.com

Mark
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

please verify it and inform me if it works
 
I am mighty! And this is a mighty small ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic