aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main"..." Watch "Exception in thread "main"..." New topic
Author

Exception in thread "main"...

Erik Evertsen
Greenhorn

Joined: Oct 08, 2004
Posts: 6
I'm getting the following error when I am starting the CLASS-file: "Exception in thread "main" java.lang.NoClassDefFoundError". What's the sollution? Thanx allready.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Muziekcalculator extends JFrame implements ActionListener{
protected JTextField cmbtextfield;
protected JTextField bfmtextfield;
protected JTextField sdtextfield;
float flcmbtextfield;
float flbfmtextfield;
float uitkomst;

public Muziekcalculator() {
super("Muziekcalculator");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container mcpane = getContentPane();
FlowLayout mclayout = new FlowLayout();
JLabel cmblabel = new JLabel("Capaciteit MB: ", JLabel.LEFT);
JLabel bfmlabel = new JLabel("Bitfrequentie Muziek: ", JLabel.LEFT);
JLabel sdlabel = new JLabel("Speelduur: ", JLabel.LEFT);
cmbtextfield = new JTextField(4);
bfmtextfield = new JTextField(3);
sdtextfield = new JTextField(8);
sdtextfield.setEnabled(false);
mcpane.add(cmblabel);
mcpane.add(bfmlabel);
mcpane.add(sdlabel);
mcpane.add(cmbtextfield);
mcpane.add(bfmtextfield);
mcpane.add(sdtextfield);
cmbtextfield.addActionListener(this);
bfmtextfield.addActionListener(this);
}
public void actionPerformed(ActionEvent mcactionevent) {
String stcmbtextfield = cmbtextfield.getText();
String stbfmtextfield = bfmtextfield.getText();
flcmbtextfield = Float.parseFloat(stcmbtextfield);
flbfmtextfield = Float.parseFloat(stbfmtextfield);
uitkomst = flcmbtextfield * 1024 / (flbfmtextfield / 8);
String stuitkomst = Float.toString(uitkomst);
sdtextfield.setText(stuitkomst);
}
}
Stefan Krompass
Ranch Hand

Joined: Apr 29, 2004
Posts: 75
Hi,

there is no main-method (at least none I can see). You need something like

Just a few annotations: Your code is more or less unreadable. If you use the code-tags provided in this forum, you increase the readability of your code a lot.
And please post code that compiles...

Stefan
Krishnan Loganathan
Greenhorn

Joined: Apr 24, 2004
Posts: 23
Hey,
In this class, you didn't declare the main method. Then, how it will come. you have to declare

public static void main(String[] args) {
}

if u want to run this class file. because, the JVM looks for the main method, and from that place only, it will start execution

Regards

Loga
Erik Evertsen
Greenhorn

Joined: Oct 08, 2004
Posts: 6
Where must I implement the code "public static void main(String[] args) {" in Muziekcalculator? In the book I have there is no main method in a program with a GUI, only in programs without a GUI. Thanx allready.
Stefan Krompass
Ranch Hand

Joined: Apr 29, 2004
Posts: 75
Hi,

since you only have a small program that displays a GUI, there is nothing wrong with implementing your main-method in the Muziekcalculator-class. Alternatively, you can write an extra class that acts as starting point for your GUI:


Stefan
Erik Evertsen
Greenhorn

Joined: Oct 08, 2004
Posts: 6
Is this allmost the correct code to start Muziekcalculator?
--------------------------------------------------------------------------
class Start {
public static void main(String[] args) {
Muziekcalculator calc = new Muziekcalculator();
calc.Muziekcalculator();
}
}
---------------------------------------------------------------------------
Getting the errors:

C:\Documents and Settings\E. Evertsen\Bureaublad\Start.java:3: cannot resolve symbol
symbol : class Muziekcalculator
location: class Start
Muziekcalculator calc = new Muziekcalculator();
^
C:\Documents and Settings\E. Evertsen\Bureaublad\Start.java:3: cannot resolve symbol
symbol : class Muziekcalculator
location: class Start
Muziekcalculator calc = new Muziekcalculator();
^
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Suggestions that you are missing a main method are incorrect.
In fact, you do have a main method - you just didn't show it in your post.
Coincidentally, your error message explicitly mentions the name of the thread executing it.

You need to:
a) Supply a complete source sample that demonstrates your problem - not just
the bit that you think is broken.

b) Give the full details of your java.lang.NoClassDefFoundError.
Specifically, the name of the class that cannot be found by the class
loader. This will appear in your error message.

c) Read. http://java.sun.com/j2se/1.5.0/docs/api/java/lang/NoClassDefFoundError.html

Good luck.


Tony Morris
Java Q&A (FAQ, Trivia)
 
 
subject: Exception in thread "main"...