繁体   English   中英

在类中找不到 main(String[]) 方法

[英]can't find main(String[]) method in class

我收到以下错误:

在类中找不到 main(String[]) 方法

import java.util.*;

class Coor {
    int x, y, w;
    Coor(int x, int y, int w) {
        this.x = x;
        this.y = y;
        this.w = w;
    }
}

class Xc {
    int c = 0;
    int d = 10;
    Xc(int c, int d) {
        this.c = c;
        this.d = d;
    }

}

public class TcsDigital {
    int n = 4;
    boolean visited = false;
    boolean[][] varray = new boolean[n][n];
    //int array[][]=new int[n][n];
    int array[][] = {
        {
            1,
            8,
            21,
            7
        },
        {
            19,
            17,
            10,
            20
        },
        {
            2,
            18,
            23,
            22
        },
        {
            14,
            25,
            4,
            13
        }
    };


    public boolean check(int r, int c) {
        if (r >= 0 && r < n && c >= 0 && c < n && varray[r][c] == false)
            return true;
        return false;
    }

    public void fun(int[][] a, int r, int c, int w) {
        if (r == n - 1 && c == n - 1) {
            System.out.println("Reached");
            return;
        }

        varray[r][c] = true;

        if (check(r + 1, c) == true) {

        }
        if (check(r - 1, c) == true) {

        }
        if (check(r, c + 1) == true) {

        }
        if (check(r, c - 1) == true) {

        }
        varray[r][c] = false;
    }
    public static void main(String[] args) {
        TcsDigital t = new TcsDigital();
        t.fun(t.array, 0, 0, t.array[0][0]);
        //Stack <Coor>stack=new Stack<Coor>();
        Stack < Xc > stacks = new Stack < Xc > ();

    }
}

发生错误 can't find main(String[]) method in class by java version 12.x 说它是什么原因,但它在onlinegdb.com , GeekforGeek-IDE 等在线编译器中编译得很好,但不能离线编译在java中,我用notepad++编程,直接在命令窗口运行

在类中找不到 main(String[]) 方法:Coor

Java 正在寻找您要编译的classname.java文件中的main方法。 文件的名称必须与在其中找到的类相对应。

我的建议是,您的文件未命名为TcsDigital.java ,因此 java 将采用它找到的第一个 java 类,即Coor 由于Coor不包含main方法,因此会发生错误。 您应该尝试将文件重命名为TcsDigital.java

我建议将每个 java 类编写在一个单独的文件中,并根据需要导入它们。 仅包含main方法的附加Main类也是一个选项。

我不知道原因,但是如果我们按照它执行的顺序将公共类排序得更高,而不会出错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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