Piyush Soni
YaBB Newbies
Offline
Posts: 22
What is wrong in this?
Nov 30th , 2007, 4:40pm
Hi, I'm new to Processing and have made a very small program but am unable to find what is wrong in this. I actually have some random files kept in my data folder C0.pts, C23.pts, C148.pts etc. (any number from 0 to 220 after C) which have some data. What my program does is try to open the files one by one on each key press, using my Polygon class. Now, I know that not all numbers from 0 to 220 are there, so I wrote a try catch block so that whichever file name is not found, it goes in the catch block and continues. ( I know what I'm doing is a very crude way of doing it but that's all right :) ) But, it opens the file C0.pts successfully, and tries only upto C5.pts and then stops!! I don't know why should it stop trying before 220!! Anyway, here's the program. I'm not supplying the class Polygon, you can replace that by any random file opening process. :- //Code starts from here boolean fileNotFound=false; int i; Polygon C; boolean keyLocked=false; void setup() { size(800,800); size(800,800); size(800,800); //Problem where processing window is opened with the default 100,100 size. C=new Polygon(); } void draw() { if(keyPressed && !keyLocked) { keyLocked=true; fileNotFound=true; while(fileNotFound) { try { println(i); C.loadPts("C"+i+".pts"); C.drawCurve(); fileNotFound=false; } catch(Exception ex) { println("Exception"); fileNotFound=true; } i++; if(i>221) i=0; println("Came here"); } } } void keyReleased() { keyLocked=false;//To take the key hit only once before releasing it } here is the output of the program: <on one key hit> 0 Came here <on 2nd key hit - exact copy paste from here including this message> The file "C1.pts" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable. 1 Exception Came here 2 Exception Came here 3 Exception Came here 4 Exception Came here 5 ________________________________________ ________________________________________ Now I don't understand, why does it stop after 5? It should continue upto file C23.pts!! (Also, it hangs after showing the above messages we can't close it by close button) I tried if Processing take a cautionary 'stop' after a few try catches, but it is not the case with simple exceptions I threw. (It must not !) I may be doing something very silly but I don't understand it so I thought may be it is something Processing specific. Please help!