vendredi 28 mars 2014

How to Solve this (J2ME) : javax.microedition.io.ConnectionNotFoundException: error 0 in socket::open


Vote count:

0




i am trying to insert Data in my DataBase using this Code but i'am getting an exception :



import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.lwuit.*;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;


public class MyMidlet extends MIDlet implements Runnable {

Form f;
TextField t1 ;
Label label1 ;
Button b1;


TextField tfNom ;
TextField tfPrenom ;


//Connexion
HttpConnection hc;
DataInputStream dis;
String url ;
StringBuffer sb ;
int ch;



public MyMidlet() {
Display.init(this);
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {

f = new Form("Test");




tfNom = new TextField("nom : ");
tfPrenom = new TextField("prenom :");

b1=new Button("ok");


f.addComponent(tfNom); // append
f.addComponent(tfPrenom);
f.addComponent(b1);


b1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {
System.out.println("gooooo");

url= "http://localhost/J2ME/ajout.php";
sb = new StringBuffer();


//****************************


try {
hc = (HttpConnection) Connector.open(url+"?nom="+tfNom.getText()+"&prenom="+tfPrenom.getText());
dis = new DataInputStream(hc.openDataInputStream());
while ((ch = dis.read()) != -1) {
sb.append((char)ch);

}
// trim tna77i les espaces
if ("successfully added".equalsIgnoreCase(sb.toString().trim())) {


System.out.println("succes (added)");


}else{


System.out.println("Error While Adding Data");

}
} catch (IOException ex) {
ex.printStackTrace();
}


//***********************


System.out.println("I am Ouuuut");


}
});

f.show();

}

public void run() {

}
}


--> It does not work and I'am getting this exception : i'am using NOKIA DevEnv for the first time. It used to work when I use it on Normal Netbeans J2ME. Can any one help ?



gooooo
javax.microedition.io.ConnectionNotFoundException: error 0 in socket::open
- com.sun.midp.io.j2me.socket.Protocol.open0(), bci=0
- com.sun.midp.io.j2me.socket.Protocol.connect(), bci=143
- com.sun.midp.io.j2me.socket.Protocol.open(), bci=122
- com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
- com.sun.midp.io.j2me.http.Protocol.createConnection(), bci=13
- com.sun.midp.io.j2me.http.Protocol.connect(), bci=138
- com.sun.midp.io.j2me.http.Protocol.streamConnect(), bci=53
- com.sun.midp.io.j2me.http.Protocol.startRequest(), bci=7
- com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=33
- com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=3
- com.sun.midp.io.j2me.http.Protocol.openInputStream(), bci=6
- com.sun.midp.io.ConnectionBaseAdapter.openDataInputStream(), bci=5
- esprit.MyMidlet$1.actionPerformed(MyMidlet.java:89)
- com.sun.lwuit.util.EventDispatcher.fireActionSync(EventDispatcher.java:312)
- com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:257)
- com.sun.lwuit.Button.fireActionEvent(Button.java:369)
- com.sun.lwuit.Button.released(Button.java:400)
- com.sun.lwuit.Button.pointerReleased(Button.java:476)
- com.sun.lwuit.Form.pointerReleased(Form.java:2059)
- com.sun.lwuit.Component.pointerReleased(Component.java:2065)
- com.sun.lwuit.Display.handleEvent(Display.java:1643)
- com.sun.lwuit.Display.edtLoopImpl(Display.java:894)
- com.sun.lwuit.Display.mainEDTLoop(Display.java:839)
- com.sun.lwuit.RunnableWrapper.run(RunnableWrapper.java:119)
- java.lang.Thread.run(), bci=5
I am Ouuuut


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire