Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

public class “Foo” must be defined in “Foo.java” I get this message even though it is in Foo.java. What gives?

0
Posted

public class “Foo” must be defined in “Foo.java” I get this message even though it is in Foo.java. What gives?

0

Ans : Javac verifies that a public class is defined in a file of the same name (e.g., that public class Foo is defined in Foo.java). Two things you can check: First, make sure the case matches exactly. public class Foo cannot be in foo.java; it has to be in Foo.java. Second, are you using MKS on win32? Javac on win32 assumes you are using the DOS path separator (\) even though MKS accepts the Unix path separator (/). When javac tries to parse a your Unix-style path, it won’t produce the correct filename, the match will fail, and it will emit an error. You have to use the DOS path separator (\), which must be escaped in MKS – e.g., “javac H:\\source\\package\\Foo.java”. Alternatively, you can traverse to each source directory and avoid pathnames altogether.

Related Questions

Thanksgiving questions

*Sadly, we had to bring back ads too. Hopefully more targeted.