• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Exception in thread "main"...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
^
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic