简体   繁体   中英

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. 这个 is his screen, where he is trying to print a line. My screen looks like 这个。 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.

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

在此处输入图片说明

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 在此处输入图片说明

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM