Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-dev] Re: problem with ASTParser parser = ASTParser.newParser(AST.JLS3);

I added the library needed for
"java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource"
 
However, I got the new error message.  But the program can run in Eclipse 3.0.      Eclipse 3.1 changed the usage model?
 
Exception in thread "main" java.lang.ExceptionInInitializerError
 at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
 at org.eclipse.jdt.core.dom.ASTParser.initializeDefaults(ASTParser.java :222)
 at org.eclipse.jdt.core.dom.ASTParser.<init>(ASTParser.java:204)
 at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:109)
 at Test.runtest(Test.java:15)
 at Test.main(Test.java:10)
Caused by: java.lang.NullPointerException
 at org.eclipse.jdt.internal.core.search.indexing.IndexManager.getJavaPluginWorkingLocation(IndexManager.java:284)
 at org.eclipse.jdt.internal.core.search.indexing.IndexManager .<init>(IndexManager.java:50)
 at org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
 at org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649)
 ... 6 more


 
On 10/22/05, zifu yang <zifu.yang@xxxxxxxxx> wrote:
I tested a simple program under Eclipse 3.1.1,
However I got the following error. Can anybody help?
According to the document, the code should run correctly.
 
The error message indicates
 ASTParser parser = ASTParser.newParser(AST.JLS3);
has problem.
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource
 at org.eclipse.jdt.core.dom.ASTParser.initializeDefaults(ASTParser.java:222)
 at org.eclipse.jdt.core.dom.ASTParser .<init>(ASTParser.java:204)
 at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:109)
 at Test.runtest(Test.java:15)
 at Test.main(Test.java:10)
 
 
 
 
Code:
 

import org.eclipse.jdt.core.dom.*;
import org.eclipse.jface.text.Document;
import org.eclipse.text.edits.TextEdit;

public class Test{

public static void main(String[] args){
 Test t= new Test();
 t.runtest();
}
 
 void runtest(){
  Document doc = new Document("import java.util.List;\nclass X {}\n");
  ASTParser parser = ASTParser.newParser(AST.JLS3);
  parser.setResolveBindings(true);
  parser.setSource(doc.get().toCharArray());
  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
  cu.recordModifications();
  AST ast = cu.getAST();
  ImportDeclaration id = ast.newImportDeclaration();
  id.setName(ast.newName(new String[] {"java", "util", "Set"}));
  cu.imports().add(id); // add import declaration at end
  TextEdit edits = cu.rewrite(doc, null);
  //UndoEdit undo = edits.apply(document);
 }
 
}


--
best regards,
Zifu Yang



--
best regards,
Zifu Yang

Back to the top