Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I fix this error "NoClassDefFoundError"

Status
Not open for further replies.

javaarray

Programmer
Feb 10, 2001
17
US
This program was working now when I try to run it, it throws this error "NoClassDefFoundError", I looked on suns site, but don't understand what is missing. Here is the code:
// ---------------------------------------------------------------------------
// Import the packages used by this class
// ---------------------------------------------------------------------------
import javax.swing.*;
import javax.swing.event.*;

import java.awt.*;
import java.awt.event.*;


// ---------------------------------------------------------------------------
// PortfolioTotalsPanel Class
// ---------------------------------------------------------------------------
public class PortfolioTotalsPanel extends JPanel
{
// Create our labels
JLabel lblDollarChange = new JLabel( "Dollar Change: $1000", JLabel.CENTER );
JLabel lblPercentChange = new JLabel( "Percent Change: 50%", JLabel.CENTER );

// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
public PortfolioTotalsPanel()
{
// Set the layout manager
setLayout( new GridLayout( 2, 1 ) );

// Add the labels to the JPanel
add( lblDollarChange );
add( lblPercentChange );
}

// -----------------------------------------------------------------------
// Main application entry point into this class
// -----------------------------------------------------------------------
public static void main( String[] args )
{
// Create a JFrame object
JFrame frame = new JFrame( "Portfolio Totals" );

// Create an PortfolioTotalsPanel Object
PortfolioTotalsPanel app = new PortfolioTotalsPanel();

// Add our PortfolioTotalsPanel Object to the JFrame
frame.getContentPane().add( app, BorderLayout.CENTER );

// Resize our JFrame
frame.setSize( 600, 100 );

// Make our JFrame visible
frame.setVisible( true );

// Create a window listener to close our application when we
// close our application
frame.addWindowListener
(
new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
 
Hi,
I do not which class is not found, but I have tested your code under JBuilder4, and it compiles without errors.
Maybe you use an old JDK, where Swing is not present, or is present under old packages(such as com.sun.java.swing.*).
Maybe you can check this.

Bye. --
Globos
 
Sorry,
I am wrong, if you have an NoClassDefFoundError exception, it is not at compile time, of course.
If you have already set a correct classpath to access to the compiled source, and you did :
$> java PortfolioTotalsPanel
I cannot help you.

sorry again
--
Globos
 
which class is not found ?
is this class in your classpath ? (answer : NO ! fix : change your classpath)

 
Have you included the current directory or the directory that contains the class that was generated when you compiled this file in the CLASS_PATH.
Just try adding .; at the begining of the classpath and see if this solves your problem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top