Compilation Error "Can not Find Symbol"

My coding took only a few years, so this question should be easy enough to answer.

I wrote two interfaces: Class and Game. The CLASS interface should extend the GAME interface.

Here are two sources of the interface:

package Impl; public interface Game { //METHODS AND VARS } package Impl; public interface Class extends Game { //METHODS AND VARS } 

Now when I try to compile the second interface, I get the following error

 class.java:4: cannot find symbol symbol: class Game public interface Class extends Game ^ 

The My Game class is compiled, and the class file is in the same directory as both java files. I could not find a solution. Does anyone have any idea?

+6
java compiler-errors
source share
2 answers

Class names are case sensitive. You may have created an interface called game , but you are referencing it in your Class interface declaration as a game that the compiler cannot find.

However, there is another chance that you compile from your Impl package. To do this, you will need to refer to your class path so that the compiler can find classes from the package structure base. You can add arg -classpath .. to your javac before the class name:

 javac -classpath .. Class.java 

Alternatively, you can do what is more common by compiling from the root of your package structure. To do this, you need to specify the path to your Class file:

 javac Impl\Class.java 

you can always add -classpath . for the cleaning.

+8
source share

You need to read how classes work Java classes, and how you should organize your source code. Basically, your problem is that when the javac compiler compiles "Class.java", it does not expect to find "Game.class" in the current directory. He (probably) is looking for him in "Impl / Game.class".

The IBM Java Path Management page contains a detailed discussion of how to set your class path and how java utilities (such as java and javac ) use it to find class files. The link " Setting the class of the path provides more detailed information in more detail ... but you need to read it carefully.

By the way, in your code you have atrocities in the style of:

  • Java package names must be lowercase.
  • Calling the Class Class is a bad idea because it interferes with the java.lang.Class class, which is imported by default.
+6
source share

All Articles