Visitar URL original
NullPointerException · Issue #24 · trung/InMemoryJavaCompiler · GitHub
The Wayback Machine - https://web.archive.org/web/20210124152029/https://github.com/trung/InMemoryJavaCompiler/issues/24
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException #24

Open
Perzan opened this issue Feb 6, 2019 · 2 comments
Open

NullPointerException #24

Perzan opened this issue Feb 6, 2019 · 2 comments

Comments

@Perzan
Copy link

@Perzan Perzan commented Feb 6, 2019 •

            `System.setProperty("java.home", "C:\\Program Files\\Java\\jdk-11.0.1");
	StringBuilder sourceCode = new StringBuilder();
	sourceCode.append("package me.Perzan.compileString;\n");
	sourceCode.append("class HelloClass {\n");
	sourceCode.append("   public static void hello() { System.out.println(\"hello\"); }");
	sourceCode.append("}");

	InMemoryJavaCompiler compiler = InMemoryJavaCompiler.newInstance();
	
	compiler.addSource("HelloClass", sourceCode.toString());
	
	
	
	Map<String, Class<?>> classMap = compiler.compileAll();
	
	Class<?> helloClass = classMap.get("HelloClass");
	Method m = helloClass.getMethod("hello");
	
	m.invoke(null);`

So at the line with 'Map<String, Class<?>> classMap = compiler.compileAll();' I get NullPointerException. I even set the property for JDK at the beginning. I'm not sure why this is happening, for my version is pretty much the same as your example...

(Also the '`' things are not part of it, I was just trying to insert the code)

Also here is the stack trace:

Exception in thread "main" java.lang.NullPointerException at org.mdkt.compiler.InMemoryJavaCompiler.compileAll(InMemoryJavaCompiler.java:80) at me.Perzan.compileString.CompileTest.main(CompileTest.java:26)

@fgMAI
Copy link

@fgMAI fgMAI commented Feb 9, 2019

I can confirm nullpointer exceptions. Only one time it worked, but i cannot Recall the difference from code.

@fgMAI
Copy link

@fgMAI fgMAI commented Feb 10, 2019

For me the Problem is that i generate unique filenames for the .java File,from input Code. With fixed names it does work.
Check the names calling.. do it like example, object names are not arbitrary - it has to match!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants