Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Runtime Exception -java.lang.NoClassDefFoundError

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Runtime Exception -java.lang.NoClassDefFoundError

    Hi,
    When I ran the applet in Eclipse, the applet worked.
    But when I try the applet in HTML, it didn't show the interface, it showed:

    Runtime Exception
    java.lang.NoClassDefFoundError: jssc/SerialPortException

    Here are my codes.

    import java.applet.Applet;
    import java.awt.Button;
    import java.awt.TextArea;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
     
    public class panel extends Applet implements ActionListener {
    	// parameters
    	Button wButton = new Button("W");
    	Button aButton = new Button("A");
    	Button dButton = new Button("D");
    	Button xButton = new Button("X");;
    	Button oButton = new Button("Start");;
    	Button cButton = new Button("Stop");
    	sd2bak SD = new sd2bak();
     
    	TextArea display = new TextArea();; // show log
    	String command = "."; // redundancy for actions
    	boolean status = false; // check connection
     
    	/** web user interface */
    	public void init() {
    		setLayout(null);
     
    		// buttons position
    		wButton.setBounds(70, 20, 50, 50);
    		aButton.setBounds(20, 70, 50, 50);
    		dButton.setBounds(120, 70, 50, 50);
    		xButton.setBounds(70, 120, 50, 50);
    		display.setBounds(200, 20, 130, 200);
    		oButton.setBounds(20, 120, 50, 50);
    		cButton.setBounds(120, 120, 50, 50);
     
    		// add buttons to Layout
    		add(wButton);
    		add(aButton);
    		add(dButton);
    		add(xButton);
    		add(display);
    		add(oButton);
    		add(cButton);
     
    		// Listen to action whenever pressed
    		wButton.addActionListener(this);
    		aButton.addActionListener(this);
    		dButton.addActionListener(this);
    		xButton.addActionListener(this);
    		oButton.addActionListener(this);
    		cButton.addActionListener(this);
     
    	}
     
    	/** Send to COM */
    	public void send(String command) {
    		SD.tocom(command);
    		command = ".";
    	}
     
    	/** Open port and socket */
    	public void openport() {
    		SD.openpt();
    		show("connected");
    	}
     
    	/** Close port and socket */
    	public void closeport() {
    		SD.closept();
    		show("Disconnected");
    	}
     
    	/** buttons action */
    	public void actionPerformed(ActionEvent evt) {
    		if (evt.getSource() == oButton && status == false) {
    			openport();
    			status = true;
    		} else if (evt.getSource() == oButton) {
    			show("Already Connected");
    		} else if (status == true) {
    			if (evt.getSource() == wButton) { // action for button w
    				command = "w";
    				work();
    			} else if (evt.getSource() == aButton) { // action for button a
    				command = "a";
    				work();
    			} else if (evt.getSource() == dButton) { // action for button d
    				command = "d";
    				work();
    			} else if (evt.getSource() == xButton) { // action for button x
    				command = "x";
    				work();
    			} else if (evt.getSource() == cButton) {
    				closeport();
    				status = false;
    			}
    		} else
    			show("Not conected");
    	}
     
    	/* actions detail */
    	public void work() {
    		// servget client_actions = new servget();
    		// send actions to server
    		send(command);
    		// send actions
    		show(command);
    		command = ".";// reset
    	}
     
    	/* display area */
    	public void show(String txt) {
    		display.append(txt + "\n");
    	}
     
    }// EOF

    import jssc.SerialPort;
    import jssc.SerialPortException;
     
    public class sd2bak {
    	SerialPort serialPort = new SerialPort("COM4");
     
    	/** Open port */
    	public void openpt() {
    		try {
    			serialPort.openPort();
    		} catch (SerialPortException ex) {
    		}
    		try {
    			serialPort.setParams(SerialPort.BAUDRATE_9600,
    					SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
    					SerialPort.PARITY_NONE);
    		} catch (SerialPortException ex) {
    		}
    	}
     
    	/** Write to COM */
    	public void tocom(String command) {
    		try {
    			serialPort.writeBytes(command.getBytes());
    		} catch (SerialPortException ex) {
    		}
     
    	}
     
    	/** Close port */
    	public void closept() {
    		try {
    			serialPort.closePort();
    		} catch (SerialPortException ex) {
    		}
     
    	}
     
    }// EOF


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,095
    Thanks
    52
    Thanked 2,284 Times in 2,255 Posts

    Default Re: Runtime Exception -java.lang.NoClassDefFoundError

    java.lang.NoClassDefFoundError: jssc/SerialPortException
    Where is the definition for the class named in the error message? Is the path to that definition included in the html file?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Runtime Exception -java.lang.NoClassDefFoundError

    Eclipse tends to include a bunch of stuff for you. When you export out of eclipse you have to make sure everything you were using in eclipse goes with it. Obviously you missed something. What it is, where to find it, and where to put it once you find it, i have no idea. Sorry.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Runtime Exception -java.lang.NoClassDefFoundError

    Quote Originally Posted by Norm View Post
    Where is the definition for the class named in the error message? Is the path to that definition included in the html file?
    Sorry, i am new in java.
    i have - import jssc.SerialPortException; Do you mean this ?

    And here's my html.
    <html>
    <head>
      <title>Hello-World Applet</title>
    </head>
    <body>
      <h3>Stream here</h3>
      <applet code="panel.class" width="350" height="250">
      </applet>
    </body>
    </html>

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,095
    Thanks
    52
    Thanked 2,284 Times in 2,255 Posts

    Default Re: Runtime Exception -java.lang.NoClassDefFoundError

    When the JVM executes the java classes it needs to find the definition for any class referenced. It looks on the classpath to find the class definiton. Where is the definition for the missing class? It's probably in a jar file.
    The jar file needs to be accessible to the JVM.
    The HTML <applet tag has an attribute for pointing to jar files that contain java classes. Find the doc for the <applet tag and read up on the attributes for pointing to jar files.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java.lang.NoClassDefFoundError exception
    By ayuda96 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 23rd, 2012, 11:12 PM
  2. [SOLVED] Exception in thread "main" java.lang.NoClassDefFoundError
    By cppcppcpp in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 26th, 2012, 11:59 AM
  3. Exception in thread "main" java.lang.NoClassDefFoundError
    By Scarice in forum Java Theory & Questions
    Replies: 25
    Last Post: July 4th, 2011, 10:02 PM
  4. Replies: 13
    Last Post: October 13th, 2010, 11:20 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM