What is the issue with importing my .java file from school into IntelliJ?


Hi there! I'm a very very new user when it comes to Java and IntelliJ. I only have recently downloaded it and are just beginning my classes of learning to use Java, however, I have run into an issue. My class requires me to download their .java file (the template they begin writing out) and I am meant to import it, finish it, and send the final product back to them once I have finished the code. Now let me walk you through my steps from downloading the "Template" to uploading it onto IntelliJ. 

1) I download the file named "TemplateLab1Bronze.java"

2) I open IntelliJ and first import "TemplateLab1Bronze", which allows me to edit the code, but does not offer the top taskbar with Run and Build (Just File, Edit, View, and Help).

3) Under File, I select "Open File In Project" which provides me with the options of Run and Build.

However, if I attempt to run the code from here, it displays this to me;

Error: Could not find or load main class IdeaProjects.TemplateLab1Bronze
Caused by: java.lang.ClassNotFoundException: IdeaProjects.TemplateLab1Bronze

How can I go about fixing this issue? I've looked and looked but am unable to find the solution. I understand this issue may be extremely easy but I'm still so new with this program and require the extra assistance. Thanks!

Comment actions Permalink

Please see https://stackoverflow.com/a/42660624/104891 .

Start with creating a new project: https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html .

Then use your favorite file manager to copy the .java file inside the project source root directory.

Comment actions Permalink

Correct me if I'm wrong but what you are suggesting is rather than trying to import the .java file and create it into a project, I'm better off creating a new project and copying in the code they supplied to me. I'm going to give this a try and see if I can make this work. Thank you for your speedy reply :)

Comment actions Permalink

Yes, I guess your source roots are not set correctly when you use the import option.


Please sign in to leave a comment.