This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes problem with HTTP connection in J2ME Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "problem with HTTP connection in J2ME" Watch "problem with HTTP connection in J2ME" New topic
Author

problem with HTTP connection in J2ME

Salman Faraz
Greenhorn

Joined: Feb 14, 2005
Posts: 28
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 ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The address is not found.

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

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Salman Faraz
Greenhorn

Joined: Feb 14, 2005
Posts: 28
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
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.


Glenn Castro<br />Sun Certified Web Component Developer
lexander Bosco
Ranch Hand

Joined: Feb 21, 2005
Posts: 65
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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Code works fine for me too. Using www.google.com

Mark
pradeep u nair
Greenhorn

Joined: Feb 24, 2006
Posts: 25
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
 
Don't get me started about those stupid light bulbs.
 
subject: problem with HTTP connection in J2ME
 
Similar Threads
javax.microedition.io.ConnectionNotFoundException: TCP open
Re: Problem about HTTP connection
Problem using http post over j2me
j2me httpconnection
Error Initializing http tunnel connection.