Hey all, I am having an issue with a NOClassDefFoundError. I am new to creating MIDlets so I am working with a textbook, Kicking Butt With MIDP and MSA and I think it's the most recent edition… not sure. At any rate I am working with the section on push registry and I've tried to compile and run the example in the text… it compiles fine, but I get a runtime error telling me that the PushRegistry class is not defined at javax.microeditoin.io.PushRegistry… ??? I've checked the JME API and as sure as the sun shines the class is defined in that package… therefore I am confused and frustrated.

If the class wasn't defined within the package shouldn't that be caught at compilation time instead of at runtime? I think that is the case so there must be something else going on that I'm not aware of... can anyone help me out with this? I'm really tired of wasting my time trying to make things do what they were intended to do instead of actually coding.

I am using NetBeans 7.1 and MPowerPlayer 2.0.1185 for my Emulator. The Error occurs at runtime immediately after the emulator is started…

here is the relevant bit of the error message…

Copying 1 file to /Users/JohnDoe/NetBeansProjects/PushRegistryExample/dist/nbrun4958300352654849687
Copying 1 file to /Users/JohnDoe/NetBeansProjects/PushRegistryExample/dist/nbrun4958300352654849687
Jad URL for OTA execution: http://localhost:8082/servlet/org.netbeans.modules.mobility.project.jam.JAMServlet//Users/rohanharrison/NetBeansProjects/PushRegistryExample/dist//PushRegistryExample.jad
Starting emulator in execution mode
mpowerplayer 2.0.1185
Error while starting midlet:
java.lang.NoClassDefFoundError: javax/microedition/io/PushRegistry
at PushyMIDlet.startApp(PushyMIDlet.java:41)
at javax.microedition.midlet.MIDlet._startApp(MIDlet.java:89)
at com.mpp.adapter.Controller._start(Controller.java:867)
at com.mpp.adapter.Controller.access$100(Controller.java:98)
at com.mpp.adapter.Controller$3.run(Controller.java:831)
at java.lang.Thread.run(Thread.java:655)

Could it be the emulator I'm using?

Hey all, I am having an issue with a NOClassDefFoundError. I am new to creating MIDlets so I am working with a textbook, Kicking Butt With MIDP and MSA and I think it's the most recent edition… not sure. At any rate I am working with the section on push registry and I've tried to compile and run the example in the text… it compiles fine, but I get a runtime error telling me that the PushRegistry class is not defined at javax.microeditoin.io.PushRegistry… ??? I've checked the JME API and as sure as the sun shines the class is defined in that package… therefore I am confused and frustrated.

If the class wasn't defined within the package shouldn't that be caught at compilation time instead of at runtime? I think that is the case so there must be something else going on that I'm not aware of... can anyone help me out with this? I'm really tired of wasting my time trying to make things do what they were intended to do instead of actually coding.

I am using NetBeans 7.1 and MPowerPlayer 2.0.1185 for my Emulator. The Error occurs at runtime immediately after the emulator is started…

here is the relevant bit of the error message…

Copying 1 file to /Users/JohnDoe/NetBeansProjects/PushRegistryExample/dist/nbrun4958300352654849687
Copying 1 file to /Users/JohnDoe/NetBeansProjects/PushRegistryExample/dist/nbrun4958300352654849687
Jad URL for OTA execution: http://localhost:8082/servlet/org.netbeans.modules.mobility.project.jam.JAMServlet//Users/rohanharrison/NetBeansProjects/PushRegistryExample/dist//PushRegistryExample.jad
Starting emulator in execution mode
mpowerplayer 2.0.1185
Error while starting midlet:
java.lang.NoClassDefFoundError: javax/microedition/io/PushRegistry
at PushyMIDlet.startApp(PushyMIDlet.java:41)
at javax.microedition.midlet.MIDlet._startApp(MIDlet.java:89)
at com.mpp.adapter.Controller._start(Controller.java:867)
at com.mpp.adapter.Controller.access$100(Controller.java:98)
at com.mpp.adapter.Controller$3.run(Controller.java:831)
at java.lang.Thread.run(Thread.java:655)

Could it be the emulator I'm using?

Here is the code from the Text Book if it helps, but I doubt that there is an error in the code… Because like I mentioned it's not a logic or complilation error, but a runime error.

[B]import javax.microedition.io.PushRegistry;[/B]
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class PushyMIDlet extends MIDlet implements CommandListener {
    protected static final String kConnection = "sms://:50000";
    
    private Display mDisplay;
    
    private Form mForm;
    private Command mExitCommand;
    
    private Command mRegisterCommand, mUnregisterCommand;
    
    public void startApp() {
        if(mForm == null){
            mForm = new Form("PushyMIDlet");
            mExitCommand = new Command("Exit", Command.EXIT, 0);
            mRegisterCommand = new Command("Register", Command.SCREEN, 0);
            mUnregisterCommand = new Command("Unregister", Command.SCREEN, 0);
            
            mForm.addCommand(mExitCommand);
            mForm.addCommand(mRegisterCommand);
            mForm.addCommand(mUnregisterCommand);
            
            mForm.setCommandListener(this);
            
            mDisplay = Display.getDisplay(this);
        }
        Display.getDisplay(this).setCurrent(mForm);
        
        try{
            [B]
            String[] connections;
            connections = PushRegistry.listConnections(false);
            [/B]
            if(connections.length > 0){
                mForm.append("Registered connections:");
                for(int i = 0; i < connections.length; i++)
                    mForm.append(" "+ connections[i]);
            }
            
            [B]connections = PushRegistry.listConnections(true);[/B]
            if(connections.length > 0){
                // We know there should be one.
                mForm.append("Connections waiting:");
                for(int i = 0; i < connections.length; i++)
                    mForm.append(" "+ connections[i]);
                
            }
        }
        catch(Exception e) { mForm.append(e.toString());}
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command c, Displayable d) {
        if(c == mExitCommand) {
            destroyApp(true);
            notifyDestroyed();
        }
        else if (c == mRegisterCommand) {
            RegisterRunnable rr = new RegisterRunnable(mForm);
            Thread t = new Thread(rr);
            t.start();
        }else if(c == mUnregisterCommand) {
            UnregisterRunnable ur = new UnregisterRunnable(mForm);
            Thread t = new Thread(ur);
            t.start();
        }
    }
    
}

class RegisterRunnable implements Runnable {
    private Form mForm;
    
    public RegisterRunnable(Form f) { mForm = f;}
    public void run() {
        try{
            [B]PushRegistry.registerConnection(PushyMIDlet.kConnection, "PushyMIDlet", "*");[/B]
            mForm.append("Registerd!");
        } catch(Exception e) { mForm.append(e.toString());}
    }
}

class UnregisterRunnable implements Runnable {
    private Form mForm;
    
    public UnregisterRunnable(Form f) { mForm = f;}
    public void run() {
        try{
            [B]PushRegistry.unregisterConnection(PushyMIDlet.kConnection);[/B]
            mForm.append("Unegisterd.");
        } catch(Exception e) { mForm.append(e.toString());}
    }
}

I Sorry but I am remembering info that may be useful to anyone trying to help after I post a message… lol. I've also checked the NetBeans 7.1 package I downloaded and MIDP 2.0.jar is bundled with the package. The PushRegisty class is defined in that API. WTF then?

Even though I don't seem to be getting any responses from any one I'll continue to update this thread with my progress. So the issue is this… I am trying to run a MIDlet that simulates sending a text message. I am using NetBeans 7.1 and my machine is a macbook. The emulators that come bundled with NetBeans don't work on mac osx, so I had to install MPowerPlayer. I needed to run the emulator via OTA in order to really see how pushregistry works and that I figured out how to do and is posted in an earlier comment.

After I installed MPowerPlayer and configured it to run via OTA, I received a runtime error when I actually tried to run the program I posted in an earlier comment. NOClassDefFoundError. After many hours of searching I finally put together a solution.

So the NoClassDefFoundError is defined at the java.lang.NoClassDefFoundError and it is thrown when a class which was available at compilation time is no longer available at runtime. Why this would happen IDK, but what ever, it's just not there. Supposedly there are tons of reasons why this could happen which make figuring out the cause all that much more difficult.

What I did is the following, but I'm not sure if it is correct because although my emulator will start when I run the program and I don't get the NoClassDefFoundError any more, the emulator it self displays a java.lang.NullPointerException on the device screen. weird.

I went to my applications folder and right clicked on the NetBeans.app (which is a directory) and choose view package contents from the list of options display in the menu that pops up.

Once inside the package I wanted to make sure that PushRegistry.class was included in the package. so I navigated my way through this rather large directory and found the midp_2.0.jar file. This is where the push registry class file should be -- packaged inside that jar file.

I then duplicated the file, because I didn't want to mess around with the original and screw something up.

with the duplicate file I expanded it in terminal with the following commmad

jar -xf midp_2.0.jar

Two new directories will appear in your pwd. I found the PushRegistry.class file at this pathname

./javax/microedition/io/PushRegistry.class

Right where it was supposed to be! So some how I needed to let NetBeans know it was there after all. In NetBeans 7.1 I opened my project and choose

file > project properties

from there I selected libraries and resources form the list marked categories and added the midp_2.0.jar file to the libraries and resources dir.

once that was done I recompiled and ran the program and it worked! Unfortunately I've run into another problem. The emulator starts and I don't get any runtime errors, but like i mentioned before, the device screen shows a message I didn't tell it to put there : java.lang.NullPointerExceptoin.

this is an Exception that is thrown when I'm trying to reference an uninitialized object so I a bit confused as to why it would be displayed on the device screen. This is where the story ends until I can figure it out or some one is kind enough to tell me the answer. I also need to learn how to get MPowerPlayer to simulate sending a text message.

Even though I don't seem to be getting any responses from any one

1)Its weekend, people in many cases are away from computers
2)People live in other parts of world beside US (I'm in UK)
3)We never said this is 24/7 coding solution forum

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.