manosagent
manosagent

Reputation: 634

Java and JFrame "NoClassDefFoundError"

I am new to Java and especially to JFRAME. I am studying about basic game development and I created a simple class to output some graphics. Here is my code:

package jframedemo;
import javax.swing.*;
import java.awt.*;

public class JFrameDemo extends JFrame {
    public JFrameDemo(){
        super("JFrameDemo");
        setSize(400,400);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }    

    public void paint(Graphics g){
        super.paint(g);
        g.setColor(Color.WHITE);
        g.fillRect(0,0,400,400);
        g.setColor(Color.RED);
        g.setFont(new Font("Arial", Font.BOLD, 18));
        g.drawString("Doing graphics with JFrame!!", 60, 200);
    }

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

Although during compile everything goes as well, when I try to execute the programm I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: JFrameDemo (wrong name: jframedemo/JFrameDemo)

I am working on Linux Mint 15 and my Java version is 1.7.0_25 OpenJDK Runtime Environment. Any suggestions why is this happening?

Upvotes: 1

Views: 1279

Answers (1)

Reimeus
Reimeus

Reputation: 159844

It appears that JFrameDemo.class is not in a folder called jframedemo as expected by the JVM. Ensure that the JFrameDemo.java is located in this folder before attempting to compile and run the application

Then your command line commands will look like

javac jframedemo/JFrameDemo.java
java jframedemo.JFrameDemo

Upvotes: 1

Related Questions