“Cannot find symbol” for my own class

旧时模样 提交于 2019-11-29 10:01:58

You need to compile from the package root, not from inside the package.

So, cd to the src folder and compile from there.

javac -cp . codejam2011/Round0/D/EntryPoint.java

Update: as per your new problem, you need to recompile Case.java the same way. It was apparently compiled the same wrong way (from inside the package).

If the problem is not yet solved by compiling from the package root directory (see the other answers):

  • make sure all the source files contain classes with names corresponding to their file name
  • make sure all the source files contain a package statement corresponding to their position in the source file hierarchy
  • delete all your .class files before compiling (this should only be necessary once, if you checked everything else).

Thus, if the file is codejam2011\Round0\D\Case.java, it should contain package codejam2011.Round0.D; as the first declaration, and then public class Case { ... }. Also, make sure there is no other source file containing this package and class declaration.

From your error message, it looks like the package statement is package codejam2011.Round0.C; instead (and you also have a class Case in the real codejam2011.Round0.C package).

You are in the wrong directory for compiling.

location: class codejam2011.Round0.D.EntryPoint

That tells me, that your package is codejam2011.Round0.D (which is against the convention (all lowercase) but beside the point ...

cd to the parent dir of codejam2011, which is src, isn't it?

javac codejam2011\Round0\D\EntryPoint.java

might do the trick.

Often you have a directory for compiled classes, like 'bin' or 'classes'. To produce the classes there, use -d (destination):

javac -d ../classes codejam2011\Round0\D\EntryPoint.java

I have similar issue, it might not apply to all cases, but what I have done is remove .gradle, build and out folder and rebuild the program again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!