Java运行时错误显示所有程序都找不到main方法。

huangapple go评论75阅读模式
英文:

Java Runtime error say main method not found for all the program

问题

我已安装了Java 8。我已经设置了类路径的环境变量。

错误:在类Test中找不到主方法,请定义main方法如下:
public static void main(String[] args)
或者一个JavaFX应用程序类必须扩展javafx.application.Application

我在编写的每个Java程序中都遇到了相同的错误。所有这些程序在其他计算机上都可以正常运行,但在我的系统中,无论我运行java ClassName,都会给我相同的错误。
我正在使用Android Studio进行Android应用程序开发,一切正常。Java IDE NetBeans和IntelliJ也都正常工作。

是什么导致了这个JRE的问题?

class Test{
   public static void main(String[] args) 
   {
    int tax=20;
    double main1=220;
    double total = main1*tax/100;
    System.out.println(total);
}}

这是一个示例程序:

使用以下命令进行编译 - javac Test.java

使用以下命令运行 - java Test

英文:

I have installed java 8. I already set the environment variables for class path.

Error: Main method not found in class Test, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

I am getting same error for every program that i have written ever in java. All these programs are working fine in other computer but in my system whenever i run java ClassName it is giving me same error.
I'm using Android Studio for android app development that is working fine. Java IDE netbeans and IntelliJ is also working fine.

What could cause this problem to JRE ?.

class Test{
   public static void main(String[] args) 
   {
    int tax=20;
    double main1=220;
    double total = main1*tax/100;
    System.out.println(total);
}}

This is a sample program:

Compiling using - javac Test.java

Running using - java Test

答案1

得分: 1

  1. 首先,通过进入 => 控制面板 > 程序,卸载 Java。

  2. 从 C: 驱动器的 programfile86 和 programfile 中删除 Java 文件夹,如果你找到一个名为 sun 的文件夹,也将其删除。

  3. 在运行中键入 appdata,这将显示一些文件夹,进入每个文件夹并删除名称为 java 或 sun 的文件。对于此目录中的所有可用文件夹都要这样做。

  4. 在运行中键入 regedit,依次进入 HKEY_USER_DATA 和 HKEY_LOCAL_MACHINE,然后进入 software,如果找到 javasoft 文件夹,请将其删除。在这两个文件夹中都要执行此操作。

在上述找到的所有内容都要删除,如果找不到也没关系,继续进行下一步。

然后重新启动您的计算机,并重新安装 Java。

英文:
  1. First of all uninstall java by going into => control panel > program

  2. delete java folder form your C: drive from programfile86 and programfile and if you find folder named as sun delete it as well

  3. In run type appdata this will show you some folder goto each folder and delete file with name of java or sun. Do this for all the folder avilable in this directory

  4. In run type regedit and goto HKEY_USER_DATA and HKEY_LOCAL_MACHINE one by one and then goto software in that delete javasoft folder if you find .. do this in both the folder

delete all the stuff mention above if you find if you don't its ok leave and move to next step.

and then restart your PC

and reinstall java

huangapple
  • 本文由 发表于 2020年5月5日 21:45:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/61614688.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定