We are about to switch to a new forum software. Until then we have removed the registration on this forum.
As an experiment i try to extend PApplet and run that.
This is the library class:
public class Problessing extends PApplet {
static public void main(final String[] args) {
PApplet.main(args);
}
}
This is my processing sketch:
import nl.doekewartena.problessing.*;
static final void main(String[] args) {
final String sketch = Thread.currentThread()
.getStackTrace()[1].getClassName();
println(sketch);
Problessing.main(sketch+".Test");
}
class Test extends Problessing {
void setup() {
println("ok");
}
}
Instead of Problessing.main(sketch+".Test");
I also tried Problessing.main("Test");
but still i get ClassNotFoundException.
Can someone help?
Answers
I'm a bit further, i had to use a
$
instead of a dot. In processing the class is found now but i get a "java.lang.instantiationException".In intelliJ it works now.
Someone an idea why processing can't make the instance?
Gonna repost what I replied in private here to help context:
Since your Problessing library is actually a hacked fork of the original PApplet,
both you and any1 trying to use it gotta struggle against Processing's pre-processor!
The pre-processor wraps up all ".pde" tabs w/
public class Name_of_1st_PDE_Tab extends PApplet {}
.Therefore, you can't change it to
extends Problessing {}
! And even Problessing.main("") gonna fail!As long Processing's pre-processor is in the way, your project is doomed! :o3
The difference between the 2 examples in your last comment is that
in Processing you are trying to instantiate an inner class
in IntelliJ you are instantiating a top-level class
I suggest you make the Test class a top level class by declaring it static and see what happens
EDIT posted before I saw GoToLoop's comment and became aware PMs
Seems like @quark got ahead of what I was already fomenting as a possible solution.
Although a heavy boilerplate to ask any regular Processing programmer to paste before using a "library"!
Below's the general recipe idea:
And now the same above adapted to the new fork library:
P.S.: Doing so, we won't be able to use multiple tabs, since they would be PApplet's nested classes!
I agree but if it just an experiment - it has some interest.
I suggest that the public access specifier is used - then it is not dependent on the pre-processor doing the job. After all we have no guarantee that the pre-processor functionality won't change.
Alternative version. Although even more boiler-plate: >-)
I'm posting a Processing's IDE oriented recipe for regular programmers. :\">
I don't wanna make the recipe even more complicated than it already is! (~~)
After all, Processing's pre-processor already place
public
in almost anything. :\">Any user for other pro IDE's already knows which ".pde" modifications gotta be done anyways! ;))
P.S.: My latest boiler-plate experiment indeed demands the
public
inclusion, so reflection works!On the other hand, directly instantiating the hacked class and passing that to runSketch() doesn't demand
public
! :PNewer boilerplate version. This time, besides not needing the name for the top-class,
we don't need for its nested class either when invoking PApplet.main("")! Check it out: \m/
Damn, it really sucks that other classes can't be used since they will be nested. Good thing is it still works in eclipse and IntelliJ.
What i can do now for example is this:
Btw, where on github can i find the code of the precompiler? I would like to have a look at it.