Buzz Black
Buzz Black

Reputation: 53

When I click a .java file, IntelliJ doesn't open it as a class

When I click on .java file I have on my computer, IntelliJ won't open it as class, so I can test it. Just red circle appears and that's it. How can I open this as a class? Here is a picture:

Upvotes: 1

Views: 8361

Answers (3)

Muath Amer
Muath Amer

Reputation: 75

You can do this by opening a new project but from an existing source, and choosing the root directory of the project you want to open (in your case the HelloWorld folder):

Project From Existing Sources

Upvotes: 1

Sebi
Sebi

Reputation: 4522

Aufgabe2.java is not in the project source directory; add it to src/ first.

On a side note, when opening a project given a source directory that has not yet been open with intellij, first, go to project structure (Ctrl+Alt+Shift+S), select your project, and in the sources tab, mark source dirs as source (blue highlight).

Upvotes: 0

Ivaylo D. Ivanov
Ivaylo D. Ivanov

Reputation: 3859

You can not simply open and run the file without creating a project with a java module. This is because to run a class IDEA needs some basic configuration, like JDK, classpath, output path etc.

This icon in your case means that Aufgabe2.java is outside of the configured "source" folders (the "HelloWorld\src" folder marked with blue). Because of that the Aufgabe2.java is not treated as a source file, so it is not compiled and cannot be run.

The simplest option is to copy the file into the "src" folder. Another option is to create brand new project with a java module and to add this file into it.

Upvotes: 1

Related Questions