简体   繁体   中英

How to resolve JLS3 cannot be resolved or is not a field error in eclipse?

import java.util.Map;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.*;

public class AST {
    public static void maain(String arge[]) {
        String str = "someString"; 
        char[] source = str.toCharArray();
     ASTParser parser = ASTParser.newParser(AST.JLS3);  // handles JDK 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6
     parser.setSource(source);
     // In order to parse 1.5 code, some compiler options need to be set to 1.5
     Map options = JavaCore.getOptions();
     JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
     parser.setCompilerOptions(options);
     CompilationUnit result = (CompilationUnit) parser.createAST(null);
}
}

I am trying to parse java code using AST PARSER in eclipse. How to resolve "JLS3 cannot be resolved or is not a field" error?

You have called your class AST so the compiler is looking for JLS3 in your AST class, not the JDT org.eclipse.jdt.core.dom.AST class.

You can either rename your AST class to something that does not clash or you can use the full name of the JDT class:

ASTParser.newParser(org.eclipse.jdt.core.dom.AST.JLS3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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