我想在我的注释处理器中从我的andoid studio项目访问资源.
我首先尝试使用filer中的getResource方法:
FileObject fo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "src/main/res/layout/activity_main.xml");
Run Code Online (Sandbox Code Playgroud)
,但它总是抛出一个异常,只是将"src/main/res/layout/activity_main.xml"作为消息返回.
接下来我想我试过了
this.getClass().getResource("src/main/res/layout/activity_main.xml")
Run Code Online (Sandbox Code Playgroud)
,但这总是返回null.
我试图使用的最后一个想法是这样的:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends File> locations = fm.getLocation(StandardLocation.SOURCE_PATH);
for (File file : locations) {
System.out.print(file.getAbsolutePath());
}
Run Code Online (Sandbox Code Playgroud)
,但它抛出一个空指针异常