HttpConnection throws NullPointerException
Hi everybody !
I'm faceing an odd problem here. I have developed an J2ME (MIDP1.0) application that, among other things, needs to comunicate with my server. The application woks fine on the emulator, it even works great on my phone (Nokia 2650) and on my partners phone (Nokia 6610), but when tested on other phones (SonyErricson, Sagem, Motorola, even an smartphone from Nokia, a 7610 i think) it throws a NullPointerException. I've run out of ideeas regading how to solve this. Here's the piece of code that bugs me:
publicvoid run(){
Pachet raspuns =null;
display.setCurrent(forma);
progress.setLabel("Trying to connect");
try{
conn = (HttpConnection) Connector.open(URL, Connector.READ_WRITE);
conn.setRequestMethod( HttpConnection.POST );
conn.setRequestProperty("Content-Type","application/vnd.wap.wmlc");
byte[] dataForSend = deTrimis.getRawData();
conn.setRequestProperty("Content-Length",""+dataForSend.length);
progress.setLabel("Sending request");
progress.setValue(25);
forma.append("Opening outputstream\n");
os = conn.openOutputStream();
forma.append("Sending data\n");
os.write( dataForSend );
forma.append("Flushing data\n");
os.flush();// this throws the exception
forma.append("Closing stream\n");
os.close();// if i remove the "os.flush()", the exception is thrown here
forma.append("Getting response code\n");
int code = conn.getResponseCode();// if i remove both os.flush() and os.close() the exception is thrown here !!!
forma.append("Response code = "+code+"\n");
progress.setLabel("Checking response");
progress.setValue(50);
if (code != HttpConnection.HTTP_OK){
thrownew Exception (conn.getResponseMessage()+"("+code+")");
}
progress.setLabel("Reading data");
progress.setValue(75);
if (!aborted){
dIn = conn.openDataInputStream();
raspuns =new Pachet();
raspuns.readPackage(dIn);
}
if (!aborted)
listener.packageReceived(raspuns);
}catch (Exception e){
forma.append("Connection failed. Reason: "+e.getMessage());
e.printStackTrace();
}finally{
cleanUp();
}
}
I really need to get this working, so could please someone give me a hint.
Thank you,
Daniel Comsa.

