File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes java lang ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "java lang ClassNotFoundException" Watch "java lang ClassNotFoundException" New topic
Author

java lang ClassNotFoundException

ThomasW Winterberg
Greenhorn

Joined: Mar 30, 2004
Posts: 2
I have made the following source code. I am sitting behind a proxy server at the university. My problem is that every time I try to connect to a url which is outside the university/outside the proxy server I cannot connect to the url e.g. when i try to connect to the following url:
String url =" http://www.cs.auc.dk/~mzinck/index.html"
I get following error:
java.lang.ClassNotFoundException: com.sun.midp.io.j2me. http.Protocol
at javax.microedition.io.Connector.openPrim(+99)
at javax.microedition.io.Connector.open(+15)
at javax.microedition.io.Connector.open(+6)
at javax.microedition.io.Connector.open(+5)
at HitMIDlet.connect(+24)
at HitMIDlet.access$000(+4)
at HitMIDlet$1.run(+7)
Exception: java/lang/ClassNotFoundException
java.lang.ClassNotFoundException: com.sun.midp.io.j2me. http.Protocol
at javax.microedition.io.Connector.openPrim(+99)
at javax.microedition.io.Connector.open(+40)
at javax.microedition.io.Connector.open(+6)
at javax.microedition.io.Connector.open(+5)
at HitMIDlet.connect(+24)
at HitMIDlet.access$000(+4)
at HitMIDlet$1.run(+7)
Exception: javax/microedition/io/ConnectionNotFoundExceptio
But when I try to connect to a server on localthost there is't a problem accessing the page on the server. So right now I can only connect to a server which is localhost (127.0.0.1)
I am using the wireless toolkit version 2. I have specifiede my proxy server ( wwwproxy.cs.auc.dk ) in the toolkit under edit - preferences - network configuration.
Is it possible to hardcode the proxy settings directly in the source code ? or what can I do to solve the problem ?
Her is my source code:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class HitMIDlet extends MIDlet implements CommandListener
{
private Display mDisplay;
private Form mMainForm;
private StringItem mMessageItem;

private Command mExitCommand, mConnectCommand;



public HitMIDlet()
{
mMainForm = new Form("HitMIDlet");
mMessageItem = new StringItem(null, "");
mExitCommand = new Command("Exit", Command.EXIT, 0);
mConnectCommand = new Command("Connect",Command.SCREEN, 0);
mMainForm.append(mMessageItem);
mMainForm.addCommand(mExitCommand);
mMainForm.addCommand(mConnectCommand);
mMainForm.setCommandListener(this);
}

public void startApp()
{
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mMainForm);
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command c, Displayable s)
{
if (c == mExitCommand)
notifyDestroyed();

else if (c == mConnectCommand)
{
Form waitForm = new Form("Waiting...");
mDisplay.setCurrent(waitForm);

Thread t = new Thread()
{
public void run()
{
connect();
}
};

t.start();
}
}

private void connect()
{
mMessageItem.setText("Connecting");
HttpConnection http = null;
InputStream iStrm = null;
ByteArrayOutputStream bStrm = null;

// When using GET, client data is stored in environment variables on the server; thus,
// there is a limit to the size of a request. With POST, because data is sent as a stream,
// there is no limit to how much data can be processed.


//InputStream in = null;
//String url = getAppProperty("HitMIDlet.URL");

// With localhost, Resin Server and a servlet on the server
//String url = ("http://localhost:8080/resin-doc/servlet/tutorial/J2METest/test");

// with localhost, Apache server and a PHP file on the server
//String url ="http://localhost/~knoppix/J2MEhello.php";

// with 192.168.195.97, Apache server and a PHP file on the server
//String url = "http://192.168.195.97/~thomasw/helloJ2ME.php";// DOES'T WORK

//String url =" http://www.cs.auc.dk/~mzinck/index.html"; // DOES'T WORK

//String url ="http://localhost/~knoppix/index.html";
try
{

// Create the connection
http = (HttpConnection) Connector.open(url);
//hc = (HttpConnection)Connector.open(url);
mMessageItem.setText("Url opened");
http.setRequestMethod(HttpConnection.GET);
http.setRequestProperty("Connection", "close");

if (http.getResponseCode() == HttpConnection.HTTP_OK)
{
int ch;
iStrm = http.openInputStream();
mMessageItem.setText("inputStream opened");
bStrm = new ByteArrayOutputStream();

while ((ch = iStrm.read()) != -1)
{
// Ignore any carriage returns/linefeeds
if (ch != 10 && ch != 13)
bStrm.write(ch);

}
iStrm.close();
http.close();
// Show the response to the user.
mMessageItem.setText(new String(bStrm.toByteArray()));

}
}
catch (IOException ioe)
{
mMessageItem.setText(ioe.toString());
}
mDisplay.setCurrent(mMainForm);
}
}
ThomasW Winterberg
Greenhorn

Joined: Mar 30, 2004
Posts: 2
I have found the answer. The reasson why i cound connect to a server outside the university is that the administration has closed all connection to servers outside the university. So instead of I installed a server inside the university. Now I can connect to the server using the servers IP adresse :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java lang ClassNotFoundException