Search code examples
javaprogram-entry-pointreturn-type

How to make main return 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

enter image description here


Solution

  • 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.