We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi.
I have made a library to enable some quicker and easier interaction. I made it in eclipse, which does not find any errors. I have also tried to import it into Processing, which at least does not seem to give an errors about importing the library or declaring class instances. But it can not use any of the methods defined in the library. For example, when I try to call a constructor:
import quickInteraction.*;
QuickInteraction qi = new QuickInteraction(this);
I get the error "The constructor QuickInteraction(PApplet) is not visible". However I know that the constructor with that parameter are in the library and both class and constructor are public.
If anyone can help, please do. And if more code pieces from the library are needed, please ask, and I shall deliver. Thank you.
Answers
Did you make it
public
?Rule of thumb -- if you are used to writing in Processing, get used to writing
public
in front of almost everything in your Java library.Ack -- sorry, you said it was public already, I somehow missed that part.
Cut a test copy of your library down to a single empty class with that constructor. Do you get the same error? If so, share the code here.
So, I removed all other classes from the .jar file than the
QuickInteraction.class
. I tested it again as before but added one of the missing classes, just but be sure:As expected it gave a "The class Button does not exist" and the "The constructor QuickInteraction(PApplet) is not visible".
This is the only class in the library:
Java is case sensitive so I would have expected it to be
QuickInteraction.class
Also I assume you are building the library in Eclipse rather than just copying the class file into the sketch?
(hint: for posting blocks of code, highlight them and hit ctrl-o. don't rely on the backticks)
Field parent shouldn't be
static
! Sometimes folks go w/ multi-windows sketches. :ar!quark, it was a typo with the lower case letter, have fixed it in the previous comment. And yes, I am coding it in eclipse, and exporting the jar file from there.
koogs, did not know, thanks.
GoToLoop, the rest of the library depends on it being static, but I do find the multiple window aspect appealing. I'll change it once I find a good way to do so.
static
from field parent.QuickInteraction.parent
throughout your code.qi.parent
.final
. >-)I agree having the parent as static is not needed but if you remove it you need to modify the constructor :-</p>
As to replacing
parent
withp
that is a matter of choice, although it saves typing having more descriptive variable names helps debugging large code bases and Eclipse does have auto complete. :)Having said all that I can see no reason why your sketch cannot find the constructor provided QuickInteraction is a top-level class i.e. defined in its own file 'QuickInteraction.java'
I am exactly accessing it as
QuickInteraction.parent
throughout the code so that every time for example a new button is made, it does not need it as a parameter.I would also have wanted it as a final but I as far I know finals have to be given a value immediately, and as such, I would not be able to set it in the constructor. Is this wrong?
But on the topic of it not working, could it be something other than the jar file? If I remember correctly in C++ you need a header file to define what methods you have in the library. But to my knowledge something like that is not needed in java nor processing, right?
It is wrong... :-\" Field initialization can be delayed till class' constructor. \m/
And for local variables, regardless they're
final
or not, they can be delayed just before they're 1st accessed. ~O)And just to cover that front too, I just write the file structure:
And inside the .jar:
There are no header files in Java or Processing.
What is the name of the file (???.java) that has the code for the QuickInteraction class?
File structure shows class folder does not match Java file name - q vs Q again. Seems like a recurring problem to check for. Methods are lowerCamelCase, classes are TitleCase -- and files match the classes they contain.
It is
QuickInteraction.java
I have also renamed all files and folders called
quickInteraction
toQuickInteraction
just to be sure.The constructor, however, are not visible.
The "quickInteraction.jar" is still all lowerCamelCase! Rename it to: "QuickInteraction.jar".
Try to recompile everything as well. And make sure the final result is: "QuickInteraction.jar".
Are you executing this statement inside the main sketch code or from inside another class?
Inside the sketch.
Create a new sketch and try and instantiate the QuickIteration object and if it doesn't work post the sketch code and the error message here
I tried to recompile it again this morning and now it works. I think it might have been a mix of a non-public constructor, letter casing and perhaps that I renamed the .jar to upper case by hand, not by eclipse.
Thank you all for your help :)