We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Processing can't find any of my sketch's classes!
Page Index Toggle Pages: 1
Processing can't find any of my sketch's classes! (Read 1032 times)
Processing can't find any of my sketch's classes!
Feb 8th, 2010, 11:21am
 
Somebody help me out here.  I've got a sketch with three additional classes, each in files outside of the main sketch file.  Yesterday, when I quit for the day, two of the three classes were implemented, the third was stubbed in (so it existed and everything) and everything was working fine.  The sketch ran without errors.

Today, I come in and start implementing the third class, called Player.  I get it to where I'm ready to run start debugging, but when I click Run suddenly processing gives me an error stating "Cannot find class or type named 'Player'", highlighting this line of code from the main sketch file:

Player[] players;

It's the first line in the whole file, which makes me suspicious.  Even more suspicious, the second line in my sketch is:

Base[] bases;

If I swap the order of those two declarations and click run, Processing still complains on line 1.  So clearly I did something wonky which has broken Processing's ability to find anything outside of the main sketch file.  I just have no idea what, or how to fix it.  Help?
Re: Processing can't find any of my sketch's classes!
Reply #1 - Feb 8th, 2010, 11:36am
 
In Processing can you see the tabs for the other classes. If not you might try the sketch | add file menu option and locate the files in your sketch folder.

Also are the 3 extra classes in .java or .pde files?
Re: Processing can't find any of my sketch's classes!
Reply #2 - Feb 8th, 2010, 11:44am
 
If I close and restart Processing, it finds the other three files just fine and opens up tabs for them.  Sketch | add file is what I used to create the other files in the first place.  This being the first time I've actually used that feature, however, I wasn't sure what file extension to use so I picked ".pde"; was that wrong?  The IDE gives no hints as to what I was supposed to choose.

But, as I said, the sketch ran just fine before I started working on the Player class today so I figured I must have guessed right about the file extension.  I have no idea what I did to suddenly confuse Processing about where these other classes are.
Re: Processing can't find any of my sketch's classes!
Reply #3 - Feb 8th, 2010, 12:13pm
 
I think the add file option is to add a pre-existing file from outside the sketch folder. To add a new tab (file) use the right arrow icon on the right hand side of the the IDE level with the tabs. This will give you the option of entering a file name.

As to choice of extension if you don't add one to the filename it will use .pde if you want a .java file then you have to add the extension yourself.

If you use a .pde extension then your class will become an 'inner class' to your main sketch. This means the code in your class has direct access to all the PApplet methods (e.g. stroke, fill, rect, text etc) and the attributes/veriables declared in your main sketch.

If you use .java then it is no longer an inner class and looses these benefits. There are advantages to having seperate .java files but thats another story.
Smiley

Re: Processing can't find any of my sketch's classes!
Reply #4 - Feb 8th, 2010, 12:47pm
 
Double check that each { matches a }
Missing that might confuse Processing, which can report an error on the wrong tab.
Re: Processing can't find any of my sketch's classes!
Reply #5 - Feb 8th, 2010, 1:17pm
 
And it's PhiLho for the win!  That did it.

Out of curiosity, is there anything to be done about giving a better error message in this situation?  In my case, the boo-boo left unbalanced braces in a class method, which means that the subsequent class method declaration should have occured in an invalid spot.  So I'm wondering why the parser didn't stop there.
Re: Processing can't find any of my sketch's classes!
Reply #6 - Feb 9th, 2010, 1:06am
 
Proper error reporting is hard to do for a compiler.
Particularly for this brace thing: if you miss one in deep level, the compiler will unroll all blocks with "bad" closing brace, so when it will discover it misses one, it will report it way later...
Page Index Toggle Pages: 1