无法运行.java文件

时间:2021-06-02 20:19:06

I might have a problem. I have homework, and I can't run the file, whenever I open the file that I downloaded it looks like this:

我可能有问题。我有家庭作业,我无法运行该文件,每当我打开我下载的文件时,它看起来像这样:

无法运行.java文件

I just can't figure it out, why it doesn't look like any normal class. Plus just for testing I wrote later the main method to try something simple, it won't even show me the option to run the file. Please any help would be really appreciated.

我只是想不通,为什么它看起来不像任何普通的类。另外,仅仅是为了测试,我后来写了主要的方法来尝试简单的东西,它甚至不会向我显示运行该文件的选项。请任何帮助将非常感谢。

(Just to be clear I am not asking help on the homework, just on the file, that I downloaded, I can't even program in the way it is right now)

(只是为了清楚我不是在家庭作业上寻求帮助,只是在文件上,我下载了,我甚至无法以现在的方式编程)

4 个解决方案

#1


The file shown Tree.java doesn't have a main method, if you want to run this file in the Editor, add the main method. Eg:

显示的文件Tree.java没有main方法,如果要在Editor中运行此文件,请添加main方法。例如:

public class Tree
{
    public static void main(String[] args)
    {
         System.out.println("Calling main");
    }
}

Refer to this link for more details.

有关更多详细信息,请参阅此链接。

#2


Two problems, the file is not on the classpath/Source Root (read this https://www.jetbrains.com/idea/help/content-root.html) and it does not have a main method.

有两个问题,该文件不在classpath / Source Root上(请阅读此https://www.jetbrains.com/idea/help/content-root.html)并且它没有main方法。

Try to create and run a new java project from the Java Hello World template or https://www.jetbrains.com/idea/help/creating-and-running-your-first-java-application.html

尝试从Java Hello World模板创建并运行一个新的Java项目,或者https://www.jetbrains.com/idea/help/creating-and-running-your-first-java-application.html

You could then copy your files into that, so that you have a following directory structure: YourProject/src/asd1/ss15/...

然后,您可以将文件复制到该文件中,以便具有以下目录结构:YourProject / src / asd1 / ss15 / ...

#3


In the side panel, go to your project files, right click the directory in which your .java files are, and

在侧面板中,转到项目文件,右键单击.java文件所在的目录,以及

"Mark directory as" >> Source code.

“将目录标记为”>>源代码。

And now you will be able to use these files as normal class files.

现在,您将能够将这些文件用作普通的类文件。

#4


I just saw your code and looks like you are far away from what you need.

我刚看到你的代码,看起来你远离你的需要。

Let me give you some tips:

我来给你一些提示:

  • Try use a good IDE like eclipse
  • 尝试使用像eclipse这样的好IDE

  • Study about how to create and use a main method
  • 研究如何创建和使用main方法

  • Study how to set in eclipse to use the main method when you run your project
  • 研究如何在运行项目时在eclipse中设置使用main方法

  • Study how to export your project a runnable jar if you are thinking in a desktop app
  • 研究如何在桌面应用程序中考虑如何将项目导出为可运行的jar

  • Check if JAVA is installed in you machine
  • 检查您的机器上是否安装了JAVA

If my question is helpful give a up vote.

如果我的问题有帮助,请进行投票。

Cheers !!

#1


The file shown Tree.java doesn't have a main method, if you want to run this file in the Editor, add the main method. Eg:

显示的文件Tree.java没有main方法,如果要在Editor中运行此文件,请添加main方法。例如:

public class Tree
{
    public static void main(String[] args)
    {
         System.out.println("Calling main");
    }
}

Refer to this link for more details.

有关更多详细信息,请参阅此链接。

#2


Two problems, the file is not on the classpath/Source Root (read this https://www.jetbrains.com/idea/help/content-root.html) and it does not have a main method.

有两个问题,该文件不在classpath / Source Root上(请阅读此https://www.jetbrains.com/idea/help/content-root.html)并且它没有main方法。

Try to create and run a new java project from the Java Hello World template or https://www.jetbrains.com/idea/help/creating-and-running-your-first-java-application.html

尝试从Java Hello World模板创建并运行一个新的Java项目,或者https://www.jetbrains.com/idea/help/creating-and-running-your-first-java-application.html

You could then copy your files into that, so that you have a following directory structure: YourProject/src/asd1/ss15/...

然后,您可以将文件复制到该文件中,以便具有以下目录结构:YourProject / src / asd1 / ss15 / ...

#3


In the side panel, go to your project files, right click the directory in which your .java files are, and

在侧面板中,转到项目文件,右键单击.java文件所在的目录,以及

"Mark directory as" >> Source code.

“将目录标记为”>>源代码。

And now you will be able to use these files as normal class files.

现在,您将能够将这些文件用作普通的类文件。

#4


I just saw your code and looks like you are far away from what you need.

我刚看到你的代码,看起来你远离你的需要。

Let me give you some tips:

我来给你一些提示:

  • Try use a good IDE like eclipse
  • 尝试使用像eclipse这样的好IDE

  • Study about how to create and use a main method
  • 研究如何创建和使用main方法

  • Study how to set in eclipse to use the main method when you run your project
  • 研究如何在运行项目时在eclipse中设置使用main方法

  • Study how to export your project a runnable jar if you are thinking in a desktop app
  • 研究如何在桌面应用程序中考虑如何将项目导出为可运行的jar

  • Check if JAVA is installed in you machine
  • 检查您的机器上是否安装了JAVA

If my question is helpful give a up vote.

如果我的问题有帮助,请进行投票。

Cheers !!