I have some java classes that work fine until I put them in a package (which they really should be in) and I can’t work out why.
Class Board
import javax.swing.JPanel;
public class Board extends JPanel {
public Board() {
}
public static void main(String[] args) {
}
}
Class Skeleton
import javax.swing.JFrame;
public class Skeleton extends JFrame {
public Skeleton() {
add(new Board());
setTitle("Skeleton");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300, 280);
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
}
public static void main(String[] args) {
new Skeleton();
}
}
And all this works fine until I put
package skeleton;
at the top of each one.
upon doing so I get
skeleton.java:9: error: cannot find symbol
add(new Board());
^
symbol: class Board
location: class Skeleton
1 error
Error: Could not find or load main class skeleton.Skeleton
Its probably something simple that i have overlooked but I can’t seem to find out what is wrong with it.
Edit
Both the classes are in a file called skeleton and skeleton is always spelled correctly.
Im am running javac on both Board.java and Skeleton.java and java on skeleton.Skeleton
EDIT 2
I fixed the
skeleton.java:9: error: cannot find symbol
add(new Board());
^
symbol: class Board
location: class Skeleton
error, I forgot I was passing each file to javac individually, but the
Error: Could not find or load main class skeleton.Skeleton
still persists.
I recreated your code in my machine and it works fine.
Named them as Board.java and Skeleton.java
Output came flashing on my screen!!
I tired this way too.
That too works.