SimonT
SimonT

Reputation: 2349

java.lang.NoClassDefFoundError when making Java package

I'm not exactly a total beginner with Java, but I'm at a loss for understanding what's going on here. When I try to compile the following code:

package controls;

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

public class RButton  {
    public RButton() {

    }
}

I get the following error:

java.lang.NoClassDefFoundError: RButton (wrong name: controls/RButton)

The RButton.java file is located in the directory "project folder\ribbon\controls\". In the Ribbon folder I've been able to successfully put package ribbon; at the top of my source files there. I can't understand what I'm doing wrong here. Any help?

Edit: The problem lies with the batch file that I use in conjunction with Sublime Text for Java source files. JCreator has no problem compiling and running. Thanks for the help. though!

Upvotes: 1

Views: 1117

Answers (1)

flavian
flavian

Reputation: 28511

The package name for classes located in the controls folder should be ribbon.controls. The folder structure is matched 1 to 1 by the package naming and hierarchy.

So in the ribbon folder, you put package ribbon. In the ribbon/controls folder, you put package ribbon.controls. In the ribbon/controls/foo folder you use package ribbon.controls.foo, etc.

Upvotes: 1

Related Questions