I have three classes. Main, Core, and Start. Here is the code for Main:
package com.leslie.quiz;
public class Main {
public static void main(String[] args) {
com.leslie.quiz.Start.main(null);
}
}
Here is the code for Core:
package com.leslie.quiz;
public class Core {
public void coldlunch() {
}
public void hotlunch() {
}
}
Here's the code for Start:
package com.leslie.quiz;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Start {
com.leslie.quiz.Core core = new Core();
float opacity = 1;
private JFrame frmCafeteriaQuiz;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Start window = new Start();
window.frmCafeteriaQuiz.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Start() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmCafeteriaQuiz = new JFrame();
frmCafeteriaQuiz.setTitle("Cafeteria Quiz");
frmCafeteriaQuiz.setResizable(false);
frmCafeteriaQuiz.setBounds(100, 100, 471, 331);
frmCafeteriaQuiz.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lblWelcomeToThe = new JLabel("Welcome to the Cafeteria Quiz! Are you a responsible hawk?");
frmCafeteriaQuiz.getContentPane().add(lblWelcomeToThe, BorderLayout.NORTH);
JButton btnIHaveCold = new JButton("I have Cold Lunch");
btnIHaveCold.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
core.coldlunch();
}
});
frmCafeteriaQuiz.getContentPane().add(btnIHaveCold, BorderLayout.WEST);
JButton btnIHaveHot = new JButton("I have Hot Lunch");
btnIHaveHot.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
core.hotlunch();
}
});
frmCafeteriaQuiz.getContentPane().add(btnIHaveHot, BorderLayout.EAST);
}
}
I'm running cmd, and changing directory to the package where all my classes are. When I run Main by typing "java Main" I get
java.lang.NoClassDefFoundError Main (Wrong Name : com/leslie/quiz/Main)
One thing I've read is that the problem could be caused by invoking the class from inside the package? It wasn't very detailed and when I ran the program from in the programs main folder, it did the same thing. If I run the program in eclipse it works great and shows no errors. And I am aware that eclipse uses a different compiler. But nothing I've tried works. Any help would be great. Thanks. :)