last day (14 days later) » 

00:10
1
Q: Unhandled exception type: InstantiationException in processing.org

Bob VerkouterenI'm trying to do a simple Class.newInstance() from within processing, but I'm failing :( code sample below of where it throws an InstantiationException. Docs said to have a public constructor and that everything would be fine, but alas. running processing 2.2.1 Codeflow: it fills up a list ...

Could you provide the message from the instantiation exception?
getMessage() was empty :( got stacktrace, but doesn't really help pastebin.com/HQbRmP9Z
Just a hunch, but could you try looping for ( java.lang.reflect.Constructor ctor : ctors ) { ctor.setAccessible(true); } and then try c.newInstance();?
Isn't that the implementation 3 lines lower with the comment, this throws as well? @hexafraction
it wasn't it. :( ;-)
No, the goal is to make all constructors accessible before trying to invoke newInstance. It may be that the first call is failing because the no-arg constructor either doesn't exist or isn't accessible, and the rest of the calls require you to pass parameters to the constructor.
00:10
* It nicely finds the Wtf class and inserts that into its classes array, the only class it calls newInstance() on is Wtf :-(
OK, my concern is that you're not getting a no-arg constructor. Let's try a little probing...
I think it's processing specific, not so much java
And I get a ctor back, can set it public, can check if it has 0 parameters
No, the reflection API in Processing should just be Java's
but then exception on instantiate
Yes, the instantiation exception is likely a cause of reflective instantiation
Can you, in your loop that tries to call all the constructors, comment out the actual ctor.newInstance() call?
Instead, could you print the value of Arrays.toString(ctor.getParameterTypes())?
00:13
I'm so used to a gui debugger these days.
if i remove both newInstance() calls both methods execute fully
comin' up, cheers :)
The reflection API will throw an InstantiationException if the parameters don't match up
Or... wait. "InstantiationException - if the class that declares the underlying constructor represents an abstract class."
Is c an abstract class?
public class Wtf implements IMenuRunnable {
public Wtf() {
}
}
Are you sure Wtf is a concrete class? Shouldn't IMenuRunnable declare some method(s) that need to be implemented by Wtf?
why? this is a test
what more does a class need then that to be a class, i can
Wtf wtf = new Wtf(); all day long
no problem
thing is an object :)
sorry, i was waiting for typelist to come through, but yeah, it's empty
OK, so no constructors declared.
00:20
because there is only empty constructor, so that is correct
println(Arrays.toString(ctor.getParameterTypes())); //empty
What do you mean no constructors declared?
Right, got confused for a sec, thought the response was empty
I'm at a loss then--the only reason InstantiationException would be thrown would be if Wtf were abstract/interface.
Does it work when you run it?
which java version should you look at the reference for anyway, half of the stuff listed on oracle isn't included :) do you know?
That does run in Java for me (I've constructed a class like this many times in basically the same way). I don't have Processing to test it
ite, fair enough, yeah in java it all just works
:( oh well, thanks for trying!
It would need to include java.lang though, and it seems that it's in fact finding the classes Class and Constructor, meaning that the functionality should be there...
Sorry I couldn't give any answer.

last day (14 days later) »