1

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.

nebuch
  • 6,475
  • 4
  • 20
  • 39

3 Answers3

1

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.

afrin216
  • 2,295
  • 1
  • 14
  • 17
1

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.

sgp15
  • 1,280
  • 8
  • 13
0

Assuming you compiled and running in the same directory:

When running then use

java -cp . skeleton.Skeleton
Edmon
  • 4,752
  • 4
  • 32
  • 42