Cant compile Java Code


#1

Hey guys , i am a beginner in Java and i got stuck while compiling a code in atom ,can anyone please help me?
I am installed the “script” package and my os is Linux mint


#2

I would suggest that you ask someone with more Java knowledge. This forum is for people using Atom and Electron, and there probably aren’t very many Java experts who hang around here.


#3

Thanks for the suggestion


#4

The error in the output shows what the problem is. It’s attempting to find the class d in the package Documents.Java.

I can also see in the screenshot that the path of the file, relative to your project in Atom, is Documents/Java/d.java. From this I can tell that the project you opened is the parent of the Documents folder, which seems to be your home folder. The Documents/Java part of the path is therefore interpreted by the script package as the Java package that your d class is in.

The script package’s documentation says the following about using Java:

Project directory should be the source directory; subfolders imply packaging.

This is exactly what’s happening. The project that you open in Atom, in your case, should be the Java folder. The d.java file will then lie directly under it in your project tree.

Java

Another way to fix this is to tell the class that it is in the package Documents.Java by adding the following to the top of the file:

package Documents.Java;

Java2

This works due to how the Java compiler maps folders to packages, but don’t do this though. Your home folder shouldn’t have been the project folder in the first place. Rather open the Java folder as the project as shown in the first screenshot.


#5

Thank you so much for the solution


#6

Sure. You’re welcome.

It might help to rather use an IDE that has good support for Java development such as Eclipse. Especially as the project gets bigger, but even for small projects it’s very convenient. Take a look at this tutorial. It’s very short and shows you how to do exactly what your code does, but with the Eclipse IDE.