Reputation: 7055
I am new to java, and I am encountering an error that (after half an hour of searching) has not revealed itself. I have two classes (this is from me following a tutorial):
Board.java:
package skeleton;
import javax.swing.JPanel;
public class Board extends JPanel {
public Board() {}
}
and Skeleton.java (I have stripped the non relevant material):
package skeleton;
import javax.swing.JFrame;
public class Skeleton extends JFrame {
public Skeleton() {
add(new skeleton.Board());
}
public static void main(String[] args) {
new Skeleton();
}
}
I compile both of them, but Skeleton gets the error that it can't find Board. Does anyone know why javac can't find a class that is right there?
Edit: They are both in the same folder named 'skeleton'. Also, my OS is windows xp prof.
Upvotes: 1
Views: 1914
Reputation: 4872
Assuming you compiled and running in the same directory:
When running then use
java -cp . skeleton.Skeleton
Upvotes: 0
Reputation: 1280
Gave it a try.
$ ls
skeleton
$ ls skeleton
Board.java Skeleton.java
$ javac skeleton/*.java
$ ls skeleton
Board.class Board.java Skeleton.class Skeleton.java
Make invoke javac command such that both .class files land up in skeleton. Also, while running make sure parent directory of skeleton is in classpath.
Upvotes: 1
Reputation: 2335
If its in the same package you don't need to use namespace to call the second class.
Try checking if Board.class
file is present in the folder. The just use new Board();
to instantiate.
Upvotes: 1