JAVA ME - Problems compiling and running (using Eclipse)

Hello,
I am new to Java ME and I am trying to run a copied HelloMIDlet application. I am getting following error when I am trying to run the application:
Running with storage root C:\Users\Niklas\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Swedish_Sweden.1252
Running in the identified_third_party security domain
java.lang.NullPointerException
     at javax.microedition.lcdui.Item.addCommandImpl(+11)
     at javax.microedition.lcdui.StringItem.addCommandImpl(+11)
     at javax.microedition.lcdui.Item.addCommand(+11)
     at HelloMIDlet.<init>(+99)
     at java.lang.Class.runCustomCode(+0)
     at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
     at com.sun.midp.midlet.Scheduler.schedule(+52)
     at com.sun.midp.main.Main.runLocalClass(+28)
     at com.sun.midp.main.Main.main(+80)
Execution completed.
3415817 bytecodes executed
17 thread switches
1667 classes in the system (including system classes)
17760 dynamic objects allocated (533540 bytes)
2 garbage collections (459436 bytes collected)And the applicaiton:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet
       implements CommandListener {
  // The exit command
  private Command exitCommand;
  // The display for this MIDlet
  private Display display;   
  // create a ticker
  private Ticker hi = new Ticker("J2ME is cool");
  public HelloMIDlet() {
    display = Display.getDisplay(this);
    exitCommand = new Command("Exit", Command.SCREEN, 2);
  public void startApp() {
    TextBox t = new TextBox("Hello MIDlet",
                "Wireless Internet", 256, 0);
    t.addCommand(exitCommand);
    t.setCommandListener(this);
    t.setTicker(hi); // set the ticker
    display.setCurrent(t);
  public void pauseApp() { }
  public void destroyApp(boolean unconditional) { }
  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
}I did try to remove as much code as possible still being able to compile it. Exactly the same type of error was presented still...
I have another MIDlet in the same projects that works fine.
What is the problem?
Thank you in advance!
Best Regards,
Niklas

java.lang.NullPointerException
     at HelloMIDlet.<init>(+99)
...Try to modify your code about as follows:
  private Ticker hi;  // initialize ticker in startApp
/* don't override the MIDlet constructor
  public HelloMIDlet() {
  public void startApp() {
    // initialize all MIDP UI stuff in startApp
    hi = new Ticker("J2ME is cool");
    display = Display.getDisplay(this);
    exitCommand = new Command("Exit", Command.SCREEN, 2);
    TextBox t = new TextBox("Hello MIDlet",
                "Wireless Internet", 256, 0);
    t.addCommand(exitCommand);
    t.setCommandListener(this);
    t.setTicker(hi); // set the ticker
    display.setCurrent(t);
//...The problem might be caused by initializing MIDP UI stuff prior to entering startApp method. I also think that overriding MIDlet constructor is not quite a good idea. Check [MIDP tutorials (Google search shows plenty)|http://www.google.com/search?q=MIDP+tutorials] if you're interested to know more details on that.

Similar Messages

  • Problems compiling and running a servlet

    I have been trying to compile and run my servlet program to no avail. Please help. I am using Tomcat 5.5 and j2sdk1.4.2
    These are the errors I keep getting. I have already set the classpath appropriately.
    MyServletTest.java:5: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    MyServletTest.java:6: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    MyServletTest.java:10: cannot resolve symbol
    symbol : class HttpServlet
    location: class MyServletTest
    public class MyServletTest extends HttpServlet {
    ^
    MyServletTest.java:13: cannot resolve symbol
    symbol : class HttpServletRquest
    location: class MyServletTest
    public void doGet (HttpServletRquest req, HttpServletResponse resp)
    ^
    MyServletTest.java:13: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class MyServletTest
    public void doGet (HttpServletRquest req, HttpServletResponse resp)
    ^
    MyServletTest.java:48: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class MyServletTest
    private void printResultSet (HttpServletResponse resp, ResultSet rs)
    throws SQLException {
    ^
    MyServletTest.java:52: cannot resolve symbol
    symbol : method prinln (java.lang.String)
    location: class java.io.PrintWriter
    out.prinln("<html>");
    ^
    7 errors

    Thank you. I have managed to compile the program but
    when I run it I get:
    Exception in thread "main"
    java.lang.NoSuchMethodError: main
    How should I run a servlet?Servlets are not run like applications. You need to deploy them to a servlet container, and they get invoked and initialized by constructor, init() method and goGet/doPost().

  • Problems compiling and running 9i forms on 10g Linux app server

    Hi all,
    we are about to move our 9i developed forms application from W2k 9ias RL2 to a 10g linux application server. It seems that we are having very much trouble with the fact that file names are case-sensitive under linux. Our forms are designer-generated and afterwards modified using forms developer under win2k. Therefore these forms have designer plls attached (OFG*.pll). In addition, we use a few custom plls and an object library (*.olb). We managed to compile our fmbs to fmx using f90genm.sh on linux, but getting FRM-40735 and ORA-06508 errors at runtime. FORMS90_PATH in default.env is correct.
    We took one fmb to narrow things down. Steps we took on development machine:
    - Rename all plls to a format of uppercase name and lowercase extension (e.g. OFGBSL.pll)
    - Reattach plls to the form
    After that
    - Move fmb and plls to linux machine
    - compile the fmb without errors
    At runtime, we get a ORA-06508 in a trigger that calls CGFK$LKUP_QRY.EXTEND_WHERE. This procedure is located in OFGTEL.pll. OFGTEL.pll has OFGMES.pll attached. We tried to compile OFGTEL.pll, but getting errors due to the fact that table CG_REF_CODES is not present in our db (we don't use it).
    Other plls like OFGBSL.pll and our custom pll work well (proved by debugging).
    Can anybody give us some hints or step-by-step instructions on how to move our application to linux, especially how to make OFGTEL.pll usable?
    Thanks in advance
    Gerald Krieger

    Here is a part of code from OFGTEL.pll
    IF (curr_value IS NOT NULL) THEN
    SELECT decode(RV_HIGH_VALUE, NULL, RV_LOW_VALUE, curr_value)
    , RV_MEANING
    INTO new_value
    , P_MEANING
    FROM CG_REF_CODES
    WHERE ( (RV_HIGH_VALUE IS NULL AND
    /* this will compare them as chars, as the */
    /* abbreviation will most often be a char */
    curr_value IN (RV_LOW_VALUE, RV_ABBREVIATION)) OR
    (to_number(curr_value) BETWEEN
    to_number(RV_LOW_VALUE) AND to_number(RV_HIGH_VALUE))
    AND ROWNUM = 1
    i think the unix .pll and Win .pll are not the same

  • Compile and run java programs using batch file

    i am using eclipse to run my java programs.How to compile and run those programs using a batch file?

    a) just write a batch file, and add it to the project. When you want to run it, go to a command window and invoke it. (There is probably also a way to invoke it from Eclipse)
    b) if the project is complicated, take a look at ant. Eclispe knows about ant files.

  • How to compile and run java files on a mac using command line?

    can someone tell me or link me to some article on how to compile and run java files from command line on a mac? I have mac OS X leopard

    What do you mean by "where to put them" ? What do you want to put anywhere ?
    Have you read Peter's comment in brackets ? Perhaps you have a classpath problem ?
    Edited by: Michael_Knight on Aug 31, 2008 4:23 AM

  • How to compile and run a java program?

    I am getting this error message, what to do?
    Exception in thread "main" java.lang.NoClassDefFoundError:
    Thanks for you help.
    Ajay

    Hello,
    I believe that this error is caused because when you
    compile and run a java program, you have to use the
    same name that is next to public class. For example,
    the program name is next to the word public class.
    For example, if a program began like this:
    public class Concat
    then the name of the program in this case is Concat
    and when you compile it you type: javac Concat.java
    when you run it type: java Concat
    depending on the name of your program.and depending on whether the class is in a package. And depending on what directory you are currently in.
    Also depending on if you set your class path you might
    have to type the above like this: jdk1.2.1\bin\javac
    Concat.java to compile, and to run you would have to
    type jdk1.2.1\bin\java Concat where you would replace
    Concat with the name of your program and replace
    jdk1.2.1 with the name of your version of java, that
    is again if you do not have your classpath set. Hope
    this helps.Your examples have nothing to do with whether the CLASSPATH is set--only with whether the PATH is set. And, it may not be jdkXXX\bin. The path to the JDK (in this case, to javac and java executables) could be anything. Classpath should be set on the command line. The OP probably did NOT set a classpath on the command line (preferred), or in the environment variables.
    Also, make sure you did not forget to put:
    public static void main(String[ ] args)
    on the line underneath the line where it says "public
    class Concat" where Concat is the name of your
    program. Again, I hope this helps.Irrelevant (with the info we have from the OP so far). The error says that the JVM can't even find the class--not that the class doesn't have a main. The "main" referred to in the error message is within the JVM itself.
    OP: Did you fix your problem? If not, what directory are your files in? Are they in a package? What command are you typing to get that error? That is, please tell us your entire command line.

  • How can I compile and run other java classes from within an application?

    Hello there everyone! I really hope that someone can help me. I am writing a program that must be able to compile and run other java classes that are in different files, much like development environments like Kawa or Forte allow you to do.
    There has to be a way of doing this ( I hope!! ), but i can't seem to find it!!
    I have tried using this command to compile:
    Runtime.getRuntime().exec ("c:\\programs\\javac className.java");
    ...and this one to run:
    Runtime.getRuntime().exec ("c:\\programs\\java className");
    ...but neither works!!! I can compile and run classes that are in the same file as my application, but I can't get it to work at all for files in different directories or files.
    PLEASE, PLEASE, PLEASE help me - i've run out of ideas, and i need this to be working in 3 days!!!
    Thank you very much for any help anyone can give me, I really appreciate it!! Thanks again!!
    Adrian ( ...in distress!! )

    public class JavaCompiler{
       public static void main(String[] args)throws Exception{ //sorry bout the laziness
          if(args == null || args.length != 1){
             System.out.println("Usage: java JavaCompiler MyClass.java");
             System.exit(0);
          String className = args[0];
          Runtime rt = Runtime.getRuntime();
          Process p = rt.exec("javac " + className); //consider setting cpath for this
          p.waitFor();
          //now try to run after it is done.
          p = rt.exec("java " + className.substring(0, (className.length() - ".java".length()));
          p.waitFor();
          //do some other stuff
    }This should get you going. You may consider looking into the System.getProperty() method in order to determine the type of OS it is running on in order to findo out what command to run. I know that the sun tool listed above is nice, but by my understanding the sun tools provided are not guaranteed to stay the same. I'm no expert on this matter, but that is one of the reasons there is no API documentation for those tools. Also, I don't believe those tools come packaged with the JRE. (Of course if you are making an IDE it will be expected that the user has an sdk installed. Good luck with figuring this thing out.

  • How to compile and run package programs in Java

    Hi,
    I want to know how to compile and run the package programs in Java using -d. instead of creating the package folder manually.
    eg:
    package Test;
    class test1
    public void disp()
    //Any code;
    I want to compile this without creating the folder ' Test ' manually. that is if we use -d with javac the Test folder will be created automatically. I need the format of -d
    could anyone please help me.
    Thanks in Advance ,
    Ambika

    My program Test.java in F:\Tomcat5\webapps\Ambika\WEB-INF\Classes. I compiled in the format below. I got like this. What should I do for this? But yesterday I compiled like this only, It compiled and the folder com\cert\Test.class is created. Today again I compiled the pgm after deleting the already created folder 'com\cert', I got the error like this.
    I've given my pgm and the thing I've got when I compiled it.
    Test.java
    package com.cert;
    public class Test
         public void display()
              System.out.println("Hai");
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>javac -d F:\Tomcat5\webapps\Ambika\WEB-INF\Classes\Test.java
    javac: no source files
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>
    Plz help me.
    thanks in advance
    Ambika

  • Compile and run java programs in different directroy

    Hi,
    I often encounter many problems when I run java programs in the different directories. Like
    javac -d dir_name a.java
    java -cp dir_name a
    Something wired often happens, such as, there is not a.java file in some directory, but javac -d dir_name a.java can still work or "java -cp dir_name a" often doesn't work. Moreover, file_name.jar is also a tough problem and solving compiling problems is often time-consuming.
    So I hope to read something about how to compile and run java programs in different directory properly.
    Could you pleae give me a detailed description for that or recommend a book or website?
    Thanks a lot.

    Can you post a small amount of code that does not work, including the directory structure, and the error messages? Some one here can likely explain the problem.

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • Java compilation and running within jsp page

    hi,
    i need of a jsp page that has a textarea in which the java coding are entered and this coding is compiled and executed. The execution result is printed.
    Please guide me.

    I don't think you can invoke java compiler or run time environment at client side (browser). Even if you use applet, i think you will not be able to do it at client side. Moreover, though java virtual machine will be available in your target user's browser, but you should not expect a java compiler in users machine.
    I have seen exam sites where they have added java code compilation and execution ability. To achieve this you can do:
    1. In your JSP page use text area where user can edit java code.
    2. Provide two buttons - 'Compile' and 'Run'.
    3. On click of 'Compile' send the code to server side. In server machine create a file in a temporary location in disk and save the code content received from client.
    4. Invoke 'javac' command (as a separate process) to compile the java class created in step 3. This process will give you error/output back which you can send back to user.
    5. In case of 'Run' you must first invoke above mentioned 'Compile' service and then another service ('Run') to actually run you java class. You can build 'Run' service in similar way.
    Here you challenge would be managing multiple client requests (to compile and run java class) at the same time.
    Code to compile and run java classes:
    import java.io.*;
    * A class to compile and run java classes.
    * @author Mrityunjoy Saha
    public class JavaProcessor{
         public static void main(String[] args){
              // Option 1 to compile and option 2 to run.
              int option=1;
              if(args.length > 0){
                   option=Integer.parseInt(args[0]);
              JavaProcessor p=new JavaProcessor();
              if(option==1){
                   p.compile();
              } else {
                   p.run();
         public void run(){
              String file="FoodTest";
              String directory="C:/Users/mrityunjoy_saha/Documents/Test";     
              executeCommand("java", directory, file);
         public void compile(){
              String file="FoodTest.java";
              String directory="C:/Users/mrityunjoy_saha/Documents/Test";     
              executeCommand("javac", directory, file);
         public void executeCommand(String command, String directory, String file){
              try{
                   String[] envp=null;
                   // Make sure that you have done Java setup in your machine.
                   // To test this try invoking javac command in command prompt.
                   Process p=Runtime.getRuntime().exec(command+" "+file,envp,new File(directory));
                   BufferedReader errorStream=new BufferedReader(new InputStreamReader(p.getErrorStream()));
                   String readData="";
                   while((readData=errorStream.readLine())!=null){
                        System.out.println(readData);
                   BufferedReader outStream=new BufferedReader(new InputStreamReader(p.getInputStream()));
                   readData="";
                   while((readData=outStream.readLine())!=null){
                        System.out.println(readData);
              catch(IOException ioe){
                   ioe.printStackTrace();
    }Thanks,
    Mrityunjoy

  • Java compile and run time questions

    Hello, I have two generic question about java compile and run:
    1. When I used javac to compile my project, it complained some classes can't be found. I added the jar file which contains these needed classes to the jre/lib/ext/ directory. The compiler no longer complains. But I'm confused. I thought the jar files in jre/lib/ext/ only used for java run time, not the compile time. Can someone help me to explain this?
    2. If I need certain user defined jar file in the classpath to compile my application, does that imply that I have to have that jar file if I want to run my project?
    Thanks in advance.

    1. lib/ext is used for generally finding classes, it doesn't matter whether you are compiling or running.
    2. Yes, you will.

  • Help:Compiling and running Java Midlets?

    Hello,
    I am a fresh learner in Java.I am finding it very difficult to compile and run Java Midlets on the Computer system.Also,i will like to tranfer the Sourcecodes to a PDA i.e install it on the PDA and have the application walking well.Please help.Thank you.

    You will get all the detailed steps ( have a look at the ff link) to configure the sun wireless toolkit on a PC , midlet compiling, running , uploading to the Palm PDA and testing it on the device. As for the connection, you can use the hot synch cable or a bluetooth hot synch.
    http://developers.sun.com/techtopics/mobility/midp/articles/palm
    Cheers!,
    Birhanu

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • How to Set up the  variables and others to compile and Run Java Programs

    Hello,
    I have just downloaded the jdk1.6.0_07 and jre1.6.0_07 and installed it in C:\Program files\Java in my Windows XP ,So please tell me how to sett up the enviroment variables etc to compile and run Java Programs from Command Prompt.
    thanks

    To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:
    1. Click Start > Control Panel > System on Windows XP or Start > Settings > Control Panel > System on Windows 2000.
    2. Click Advanced > Environment Variables.
    3. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
    C:\Program Files\Java\jdk1.6.0_<version>\bin

Maybe you are looking for

  • External access to TC with my macbook

    My TC is operating in bridge mode behind a fritz box that provides the www. I do not manage to enter by "access to my mac" using any www connection from the outside. The ports UCP 5353 to 5353, 4500 to 4501 and TCP 5354 to 5354 are forwarded into the

  • Exits in transaction HUPAST

    Hi, I'm using transaction HUPAST and it is a business requirement to set the fields 'Total Weight' and 'Weight Unit' to obligatory?  I tried with a field exit, but for some reason it did not work. Then I tried using all of the Badi_hu*, but i couldn´

  • Change of properties for %RT formula

    I am using the %RT formula in a query and also using the properties of Calculate Single Value As - Normalize Sub Totals.  When I do this it automaticly returns the figure to 3 decimal places and adds % at the end. I have the properties of this formul

  • Export tables from one db to another

    Hi, I would like to copy/export a table of X database to Y database. Is it posible to use an export statement using SQL command so that I could use it in my profram (as I have sevral tables to export) in a loop. Tnx Paps

  • Why does firefox makes multiple profiles

    My name is Mike from the helpdesk of YER. We have one user with the same problem over and over again. Our employees have a roaming profile with multiple browsers, but he uses Firefox wich is causing a problem. There is a datalimit on our user profile