This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes ConnectionNotFoundException please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "ConnectionNotFoundException please help" Watch "ConnectionNotFoundException please help" New topic
Author

ConnectionNotFoundException please help

jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Well i was making the following program:
which is also in tutorial
public class FirstExample extends MIDlet {
private Display display;
String url = "http://127.0.0.1:8080/examples/t.txt";
public FirstExample() {
display = Display.getDisplay(this);
}
/**
* This method is invoked when the MIDlet is activated
*/
public void startApp() {
try {
getViaStreamConnection(url);
} catch (IOException e) {
//Handle Exceptions any other way you like.
System.out.println("IOException " + e);
e.printStackTrace();
}
}
/**
* Pause, discontinue....
*/
public void pauseApp() { }
/**
* Destroy cleans up everything.
*/
public void destroyApp(boolean unconditional) { }
/**
* read url via stream connection
*/
void getViaStreamConnection(String url)
throws IOException {
StreamConnection c = null;
InputStream s = null;
StringBuffer b = new StringBuffer();
TextBox t = null;
try {
c = (StreamConnection)Connector.open(url);
s = c.openInputStream();
int ch;
while((ch = s.read()) != -1) {
b.append((char) ch);
}
System.out.println(b.toString());
t = new TextBox("hello....",
b.toString(), 1024, 0);
} finally {
if(s != null) {
s.close();
}
if(c != null) {
c.close();
}
}
// display the contents of the file in a text box.
display.setCurrent(t);
}
}
It gives follwing exceptions.While when i cal that t.txt file from IE5.0 It works but here it gives exception.Please Help.
javax.microedition.io.ConnectionNotFoundExceptionjavax.microedition.io.ConnectionNotFoundExceptionat com.sun.cldc.io.j2me.socket.Protocol.openPrim(+7)at com.sun.midp.io.InternalConnector.openPrim(+180)at com.sun.midp.io.InternalConnector.openInternal(+20)at com.sun.midp.io.j2me.http.StreamConnectionPool.createStreamConnectionElement(+140)at com.sun.midp.io.j2me.http.StreamConnectionPool.getConnection(+121)at com.sun.midp.io.j2me.http.Protocol.connect(+64)at com.sun.midp.io.j2me.http.Protocol.sendRequest(+90)at com.sun.midp.io.j2me.http.Protocol.openInputStream(+48)at FirstExample.getViaStreamConnection(+30)at FirstExample.startApp(+8)at javax.microedition.midlet.MIDletProxy.startApp(+7)at com.sun.midp.midlet.Scheduler.schedule(+225)at com.sun.midp.dev.DevMIDletSuiteImpl.schedule(+7)at com.sun.midp.Main.runLocalClass(+20)at com.sun.midp.Main.main(+68)Execution completed successfullyimport java.io.*;
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
Did you enable TCP/IP networking for your emulator and the OS running on your emulator?


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Well i am using sun j2mewtlkit(motorola i85s).I can't find option where to enable tcp/ip.Can u please tell.
Thanks
 
 
subject: ConnectionNotFoundException please help