如何使主函数返回 char[]。

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

How to make main return char[]

问题

我正在制作一个用于读写 XML 文件的程序,问题是我称之为 "initializer" 的这个程序将被另一个我称之为 "machine" 的程序调用,并且 initializer 必须向 machine 返回一个字符数组。
以下是主要函数:

public static char[] main(String[] args) throws SaxonApiException, IOException, NoSuchMethodException {
    define elementos = new define();
    if (args.length >= 1) {
        file = args[0] + ".xml";
    } else {
        System.out.print("Não foram encontrados argumentos\n");
        exit(200);
    }
    Document doc = inicialização.pos.XMLJDomFunctions.lerDocumentoXML(file);
    if ("adiciona".equals(args[1])) {
        if (args.length >= 3) {
            doc = adicionaTabelaFicheiro(args[2].split(" ")[0], args[2].split(" ")[1], doc, elementos);
            String c = "0";
            return c.toCharArray();
        }
    }
    if ("altera".equals(args[1])) {
        if (args.length >= 3) {
            doc = alteraTabelaFicheiro(args[2].split(" ")[0], args[2].split(" ")[1], doc, elementos);
            String c = "0";
            return c.toCharArray();
        }
    }
    if ("le".equals(args[1])) {
        if (args.length >= 3) {
            char[] c;
            c = leTabela(args[2].split(" ")[0], doc, elementos);
            return c;
        }
    }
    String c = "400";
    return c.toCharArray();
}

正如你所看到的,主函数的返回类型是 char[],但当我尝试运行它时,它显示找不到主类。

英文:

I'm making a program to read and write to xml files the problem is that this program, which I'm calling initializer, is going to be called by another program, which I'm calling machine, and the initializer has to return a char array to the machine.
Here is the main function:

public static char[] main(String[] args) throws SaxonApiException, IOException, NoSuchMethodException {
define elementos = new define();
if (args.length >= 1) {
file = args[0] + ".xml";
} else {
System.out.print("Não foram encontrados argumentos\n");
exit(200);
}
Document doc = inicialização.pos.XMLJDomFunctions.lerDocumentoXML(file);
if ("adiciona".equals(args[1])) {
if (args.length >= 3) {
doc = adicionaTabelaFicheiro(args[2].split(" ")[0], args[2].split(" ")[1], doc, elementos);
String c = "0";
return c.toCharArray();
}
}
if ("altera".equals(args[1])) {
if (args.length >= 3) {
doc = alteraTabelaFicheiro(args[2].split(" ")[0], args[2].split(" ")[1], doc, elementos);
String c = "0";
return c.toCharArray();
}
}
if ("le".equals(args[1])) {
if (args.length >= 3) {
char[] c;
c = leTabela(args[2].split(" ")[0], doc, elementos);
return c;
}
}
String c = "400";
return c.toCharArray();
}

As you can see here the main has char[] returning type but when I try to run it says no main classes found

如何使主函数返回 char[]。

答案1

得分: 1

以下是翻译好的内容:

Java中的主方法必须如下所示:

public static void main(String[] args) {...}

它没有返回类型。我建议您尽可能地重命名您的方法。但请记住,您必须在某个地方定义您的主方法以便执行程序。

英文:

The main method in Java must look as follows:

public static void main(String[] args) {...}

It doesn't have a return-type. I would suggest you to rename your method, if possible. Still bare in mind that you have to define your main method somewhere in order to execute the program.

huangapple
  • 本文由 发表于 2020年9月17日 19:43:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63937316.html
匿名

发表评论

匿名网友

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

确定