Makhtar
Makhtar

Reputation: 3

IntelliJ Idea unable to execute java Program

I am trying to learn Java from an online class, however I am having problems following the instructor's video. This is his screen, where he is trying to print a line. My screen looks like this. As you can see, the "out" part of System.out is not the same on our screens, and the icon for class is different on both our screens as well. The main problem I am having is I'm not able to run the line of code that I wrote. I apologize if this question has been asked already, I was not sure what keywords I would use to search this problem.

Upvotes: 0

Views: 666

Answers (2)

dumbPotato21
dumbPotato21

Reputation: 5705

As you can see, the "out" part of System.out is not the same on our screens

This probably is due to the fact that you haven't opened up a Java Project. As you can probably see in the Two Images, the instructor's image, has A Project hierarchy on the left, while yours is empty. Therefore, To correct this Try The Following Steps:

File->New Project->Java Project

Now follow the onscreen instructions to create the Java Project. Then the project would be created. Now expand the project on the left pane, and do it until you find a folder named src . Select the folder, and choose new Class, and then You can create your new Classes

The main problem I am having is I'm not able to run the line of code that I wrote.

This is probably due to the fact that you Have not set up your JDK path in IntellIJ. This is backed up by the fact, that your run button (The Green Arrow on the Instructor's), is grayed. To fix this, click On the small Button beside the arrow. There, Click On edit Configurations. The following Window should pop up

enter image description here

If Default is not expanded, then expand it and Choose Application. The Window Should probably be like this :-

Then Click On the plus icon on the top

There, Enter You Main Class(The Class Which has public static main void(String args[]))

If you can't, choose the ... option, and choose enter image description here

Finally, select the JRE path, that is, the location where you installed The JRE.

Also, make sure that You have the 'path' environment variable set to the bin of your jdk Installation Folder.

Ask if you have any problems doing this.

Upvotes: 2

bobryash
bobryash

Reputation: 149

First you shoud do this: File- New- Project... Then create new project. And then you click right mouse button on src folder(in your new project), choose new "Java class" and copy code to that new class. And then you'll be able to run your main method.

Problem is that you just use java-file from somewhere (desktop, probably), but you should have it inside your project.

Upvotes: 0

Related Questions