Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I don't know what to do!

 
elli geo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
that's my first try to write a program in j2me and of course it's without success . i can compile my code without any problems but i can't run it,PLEASE help me if you can!!! that's the the exception:
startApp threw an Exception
java.lang.NullPointerException
java.lang.NullPointerException
at Test3MIDlet.startApp(+6)
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)
and that's my code:
import javax.microedition.io.Connector;
import javax.microedition.io.DatagramConnection;
import javax.microedition.io.Datagram;
import javax.microedition.io.Connection;
import javax.microedition.midlet.MIDlet;
import java.io.IOException;
import java.io.DataOutputStream;
import java.io.DataOutput;

public class Test3Main
extends MIDlet
implements Connection {

Datagram elliData = null;
DatagramConnection dc = null;

public void startApp () {
try {
dc = (DatagramConnection)Connector.openDataOutputStream("127.0.0.1:1234");
elliData = dc.newDatagram (40, "datagram://127.0.0.1:1234");
elliData.writeChars ("Uhuuuu!");
}
catch (IOException o) {
System.err.println ("0");
}
try {
Connector.openDataOutputStream ("127.0.0.1:1234");
dc.send (elliData);
dc.close ();
}
catch (IOException ioe) {
System.err.println("3");
}
}

public void pauseApp() {
}

public void destroyApp( boolean unconditional) {
}

public void close () {
}
}
thanks!!!
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh god in first try of j2me application directly you jumped to the DataGram Connection, wow!! Great.......
Well, after reading your posting i have to ask some question before giving any suggession
1-Are you running you application on emulator or the real phone
2- If you are running it on emulator then whether your machine is in network or standalone

One sugession is : I think problem is you don't have to show anything at the screen of the midlet so please add atleast one object which can be the current screen for this midlet in the startApp method using following code
Display d=Display.getDisplay(this);
d.setCurrent(current_object);
Rishi
 
elli geo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi and thanks for the sugession!
1. yes i'm running the application on emulator
2. my computer is in network.
this what i posted you is just the client and i know it won't run as it has to because i haven't still program the server. i ran it because i wanted to see if that's the right way to program such kind of programs and if the way i'm thinking is right so that i can start programming the server or everything i've done is false.
thx a lot!!!
elli
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic