Loading...
Logo
Processing Forum

How to debug a SketchException

in General Discussion  •  Other  •  1 year ago  
Hello,

I have been working on a fairly large project using Processing and just recently I've run into this error message:

processing.app.SketchException: unexpected token: .
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:326)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
at java.lang.Thread.run(Thread.java:662)

I am running my program in the Processing IDE and when this fail occurs it takes me to the end of one of the code tabs.  But, the code in that tab has not changed for quite some time and I don't see anything obviously wrong with my code.

Any ideas for how to figure out what exactly is causing this error?  

At this point, I may have to check out previous versions of code and compare the changes, but that could be painful.  I imagine it's something dumb that I did, but haven't found it yet.

I am running Processing 1.5.1 on Windows 7, with Java 1.6.0_27.

tia,
bbc

Replies(15)

Common issue, and hard to find out, indeed. Often, the error can be in the first tabs, but propagates in the next until it is raised in one of the last tabs. Or the reverse!
I opened one of my sketches with many tabs. I just removed a semi-colon on a line in the fourth tab. I get an error on the second tab, at the start of the last declared class.

A possible solution is to hit Ctrl+T in each tab. If you get a funny formatting, there might be a syntax error in that tab.
Or indeed, compare the files, and double check the syntax of each change.
Thanks for the tip!

It was pebkac, I finally found a common syntax error.  
Hi Guys, this catched my eye, because no later than yesterday I spent 3 hours chasing syntax errors. My project, too, is getting on the heavy side, and will only grow...
So, in search for a better editor, I started experimenting with Eclipse...But I am concened that Java will add its own drag, and that I will loose the "relaxed" PDE of Processing. 
SO, do you think it is worth it ? 
Thanks 
If your project becomes big, using a real IDE can be a boost of productivity, even if "real" Java can add a bit of syntax, but overall it is well worth: Eclipse, for example, offers auto-completion, so you have less to type, and can catch syntax errors earlier and in a more precise way. But you might have to start making a file per class, to use visibility modifiers (public, private, ...) and so on.
Thks phi.lho. It kinds of confirms my feeling. 
Some approaches to try:

1. Compile often to avoid them.

2. When they occur think hard about what code has recently changed. The compiler gets in a mode looking for the end of an expected syntax and just keeps looking and looking, thus announcing an error in a tab what hasn't changed. So focus on the recent edits.

3. narrow in on the area of the problem. Possible methods:
a. insert a clear error, like 
xxx
and see if the compiler sees it. If not keep moving the error  up/down until it is discovered. Then start inserting in the opposite direction until you have a small area. Visually inspect the code looking for open ended syntax.

b. Use multi-line comments
/*

*/

and comment out sections of code until you get a clean compile .Then move the comment edge making more code visible to the compiler until the error occurs. When the area appears the recently revealed code is the problem. If this is large narrow in by move the comment ends. Then visually inspect looking for the problem.This can be very effective except when commented out code causes other errors due to unresolved references cause by the loss of the code.
-------------------
More often then not that newly added function or method  is the issue because of an open ended syntax error. So thoughtful reflection on what has changed recently and visual inspection more often gets the job done.

Compile often and early to keep the scope of the problem area small.



Agree on all that. 
Thanks Jas, placing the intentional error in different locations and commenting out code makes a lot of sense, if necessary.      

"Thinking hard about what has changed" was hard in this case because (ashamed to even say this!) I wrote myself a comment as an intentional error so I would remember what I was focusing on when I came back to the project awhile later.

I really enjoy the code completion and better error checking provided by Eclipse, but for Processing I haven't made the best use of it yet.
bbcannon said: "I wrote myself a comment as an intentional error so I would remember what I was focusing on when I came back to the project awhile later."

Alternate approaches:

1. Add a comment with 
/ / ToDo: need to do whatever
at the location and look for ToDO's later

2. Have a multi-line comment at the head of the project where plans are outlined:
/*=====Plans and objectives =====================
Need to
1. split whatEver logic in own class
2. optimize search method
3. fix selection transition bug in tab whatEver,
4. etc.
==========================================*/
This can be very helpful when one thinks of things that need doing, or gets an idea, but puts them off for the moment.

3.Your approach mentioned above; create a compile time error, just be sure it is not s syntax error. Something like
 x = compilerError;
where comilerError is not declared.



wouldn't that tread be great tutorial or Wiki ?

proposal.


Jas,  I should have gone with option #3 in this case.  Makes sense to create an error that gets past the lexer.  Your other suggestions make a lot of sense also.


You should also try the wonderful Sketch Outline tool for processing.
If you have syntax errors in your sketch it will tell you the line and the tab of the error.
Very useful.

Re: [WatchList] How to debug a SketchException

1 year ago   - via EMail-to-forum

Sorry, what is the link for that?

Re: [WatchList] How to debug a SketchException

1 year ago   - via EMail-to-forum

Thanks a lot!