I have used ANTLR to parse Java code and everything works well. But the problem is getting the following error when I run it in on a Mac:
javac -cp antlrworks-1-1.4.3.jar *.java
Main.java:18: cannot find symbol
symbol : method javaSource()
location: class JavaParser
CommonTree tree = (CommonTree)parser.javaSource().getTree();
^
1 error
The Java grammar you are using does not have a rule called javaSource, so no method with that name exists in the generated code. Some other Java grammars I have seen use compilationUnit, but without seeing your grammar there's no way to tell you exactly how to fix this.
Related
I teach a Java-based Advanced Computer Science class and we primarily use the Eclipse IDE. I recently had an assignment where students explored regex in Java, and have run into an issue where incorrectly formed escape sequences actually pass in Eclipse, but fail java compilation when running through my test automation. Here is an example of a regex that should fail but does not on eclipse:
in = in.replaceAll(" ([^\s]*([^0-9\\+|\\-|\\/|\\(|\\)|\\*|\\.|\\s]+|[^0-9]\\.|\\.[^0-9])[^\s]*) "," Error:$1"+separator+" ");
When compiling outside of eclipse, this code correctly fails to compile with the following error message:
RegularExpressions.java:60: error: illegal escape character
in = in.replaceAll(" ([^\s]*([^0-9\\+|\\-|\\/|\\(|\\)|\\*|\\.|\\s]+|[^0-9]\\.|\\.[^0-9])[^\s]*) "," Error:$1"+separator+" ");
^
I have been unable to figure out why eclipse ignores this issue. I am assuming that there is some setting somewhere that I need to update, but I have not found it yet. It is particularly frustrating for students when their code "works for them" but then fails my testing.
Any help would be greatly appreciated.
\s is a valid Java escape for space in Java 15 and later (JLS ยง3.10.7)
There is a bug in Eclipse see here which accepts \s when the language level is less than 15. This will be fixed in 2021-12 (4.22)
I'm trying to compile a simple latex using LaTexTools package, and when I press cmd-B, I get the following error. I've googled this error and all the answers I've read have to do with java files, which I don't have here. I'm not sure how I should go about fixing this.
Error: Could not find or load main class test
[Finished in 0.1s with exit code 1]
[cmd: ['java', 'test']]
[dir: /Users/Username/Desktop]
[path: /Users/Username/Projects/reedsnotes/google-cloud-sdk/bin:/Users/Username/opt/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin]
I am trying to compile LoginTest_Chrome.java using javac at Windows command prompt. Prior to this, I have set my Environment's classpath to be associated with all the .jar library files, such as Apache POI and Selenium.
Using echo %classpath%, this is the result of my classpath Environment:
Then, I execute javac LoginTest.java and I got the following result:
Hope to have advice from experts here on how to resolve this issue which has bugged me for two days.
Error message after javac *.java:
Start.java:63: error: cannot find symbol tc = row.getCell(0).toString();
^ symbol: variable tc location: class Start
Start.java:64: error: cannot find symbol username = row.getCell(1).toString();
^ symbol: variable username location: class Start
Start.java:65: error: cannot find symbol password = row.getCell(2).toString();
^ symbol: variable password location: class Start
The problem is not with the compiler itself but with your source code. If you take a look at the first Error it says
LoginTest_Chrome.java:76: error cannot find symbol
LoginCredentials.getFile();
which means that the LoginCredentials variable you are trying to use at line 76 wasn't declared somewhere, or it's somewhere the compiler can't see it (in another .java file maybe?)
All the other errors mean the same.
So, here's my problem. I've got my ANTLR4 code successfully compiled, without errors and now I want to test it out. The ANTLR4 Documentation tells me, to test my applications, I shall do this:
java org.antlr.v4.runtime.misc.TestRig
I've tried this and got following error:
Error: Main Class org.antlr.v4.runtime.misc.TestRig couldn't be found or load.
I've checked if my CLASSPATH wasn't set, but everything was correctly set as it should be. I also tried moving the file directly to my test folder and opened CMD there and tried it again, I occur the same error. Searching in the Internet didn't help, as no one seemed to have occurred this error with ANTLR4 before.
Specs:
Java 1.7.0.55
ANTLR 4.4
There seems to be something wrong with your classpath, contrary to your belief everything is okay.
When I download the ANTLR 4 JAR and run TestRig:
wget http://www.antlr.org/download/antlr-4.4-complete.jar
...
java -cp antlr-4.4-complete.jar org.antlr.v4.runtime.misc.TestRig
I see the following on my console:
java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName
[-tokens] [-tree] [-gui] [-ps file.ps] [-encoding encodingname]
[-trace] [-diagnostics] [-SLL]
[input-filename(s)]
Use startRuleName='tokens' if GrammarName is a lexer grammar.
Omitting input-filename makes rig read from stdin.
I am following this tutorial to implement a server and client using jacorb. I used the same code and in step 2 when I want to compile the generated server.java class I got this error
javac server.java
server.java:11: cannot find symbol
symbol: class serverOperations
extends serverOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity
^
1 error
Add the directory containing the generated stub and skeleton code to your classpath. The JacORB jar is also required
javac -cp /path/to/stubcode:jacorb.jar:. Server.java
I would recommend asking questions about JacORB on the jacorb-developer list (http://www.jacorb.org/contact.html)