0

i am trying to learn how to use ANTLR, so I tried to run an example from the book , but the the cmd is telling me: "Could not find or load main class Test". Could someone tell me what I did wrong. Thanks in advance

package antlrs;


import org.antlr.v4.runtime.*;

public class Test {
    public static void main(String[] args) throws Exception {
        CharStream inputStream = CharStreams.fromFileName("firstTest.txt");
        ArrayInitLexer lexer = new ArrayInitLexer(inputStream);
        ArrayInitParser parser = new ArrayInitParser(new CommonTokenStream(lexer));
        parser.addParseListener(new ArrayInitBaseListener());

        parser.init(); 
    }}
Keitos
  • 1
  • The classes name is actually `antlrs.Test` not `Test`. – Stephen C Oct 19 '20 at 07:34
  • @Stepen C I also tried that, but i get the same Error – Keitos Oct 19 '20 at 07:38
  • OK, so read the linked Q&A. And also read up on how that Java classpath works. (There are links in the linked Q&A.) I expect that the problem is that you didn't follow the instructions in the book **precisely**. (If you told me which book / where the instructions are, I could check that they are correct.) – Stephen C Oct 19 '20 at 07:39
  • 1
    Hint: this is super basic java. If you dont understand what is going on here, I suggest you postpone ANTLR for a few days. Seriously. Rather start with a HelloWorld. And learn how you get from a java source file to .class files, and how to run that correctly on the command line. – GhostCat Oct 19 '20 at 07:41
  • 1
    What I mean is: there is no point in learning how to use a specific Java tool ... when such basics still give you trouble. – GhostCat Oct 19 '20 at 07:42
  • (After HelloWorld, do HelloWorld in a package ...) – Stephen C Oct 19 '20 at 07:42

0 Answers0