JavaCompletions icon indicating copy to clipboard operation
JavaCompletions copied to clipboard

NullPointerException when trying to get completions

Open PranavPurwar opened this issue 3 years ago • 1 comments

I'm unable to use this library in my project.

Whenever I try to run the sample project, it just throws an NPE saying treePath is null, I tried searching for the cause of this issue but it refers to AutoValue_PositionContext.java which is auto-generated by the AutoValue annotations library. Here's the code I'm currently using

JavaCompletions completions = new JavaCompletions();
completions.initialize(new File(/* Path to the directory containing the sample java files */).toURI(), new JavaCompletionOptionsImpl(getBinDir() + "log.txt", Level.ALL, null, null));
// As a sample test
CompletionResult result = completions.getProject()
                .getCompletionResult(new File(currentPathOfFile).toPath(), 8 /** line **/, 13 /** column **/);
 
String s = "";

for(CompletionCandidate candidate : result.getCompletionCandidates()) {
    s += candidate.getName();
    s += "\n";
}
/* Do something with the completion list later on */

Note: I modified the library to use com.sun.* and javax.tools.* packages instead of org.openjdk.* and org.openjdk.javax.* packages by mass search and replace Screenshot_2022-05-06-18-06-53-437_com pranav java ide Screenshot_2022-05-06-18-07-18-709_com pranav java ide

PranavPurwar avatar May 06 '22 12:05 PranavPurwar

the NPE was caused my the modification of the packages, please try using the ones that is packaged in the library because thats the one that is tested.

tyron12233 avatar May 07 '22 15:05 tyron12233