|
Author |
Topic: Unhelpful Error (Read 266 times) |
|
jbk303
|
Unhelpful Error
« on: Feb 24th, 2004, 4:41am » |
|
I am writing a polygon class for geometry class (Ha. Double ha.) I wrote this code: Code: Shape shape = new Shape(5); void setup(){ size(300,300); ellipseMode(CENTER_RADIUS); //necessary } void loop(){ shape.update(); shape.display(); } class Shape{ int[] x; //point x coords int[] y; //point y coords int verts;//num vertices Shape(int num){ x = new int[num]; y = new int[num]; verts=num; for(int i=0; i<num; i++){ //Choose all the point locations while(!mousePressed){ ellipse(mouseX, mouseY, 10, 10); } x[i] = mouseX; y[i] = mouseY; } } void update(){ for(int i=0; i<verts; i++){ if(mouseX < x[i]+5 && mouseX > x[i]-5 && mouseY < y[i]+5 && mouseY > y[i]-5){ while(mousePressed){ //Move the points around with the mouse WILL GET STUCK TOGETHER FIX x[i]=mouseX; y[i]=mouseY; } } } } void display(){ for(int i=0; i<verts; i++){ ellipse(x[i], y[i], 10, 10); line(x[i], y[i], x[(i+1)%verts], y[(i+1)%verts]); //Draw lines between adjacent vertices } } } |
| and recived this very helpful (Ha. Double ha.) error message: Code: java.lang.NullPointerException at PdeRuntime.start(PdeRuntime.java:345) at PdeEditor.doRun(PdeEditor.java:801) at PdeEditorButtons.mouseReleased(PdeEditorButtons.java:418) at java.awt.Component.processMouseEvent(Component.java:5134) at java.awt.Component.processEvent(Component.java:4931) at java.awt.Container.processEvent(Container.java:1566) at java.awt.Component.dispatchEventImpl(Component.java:3639) at java.awt.Container.dispatchEventImpl(Container.java:1623) at java.awt.Component.dispatchEvent(Component.java:3480) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095) at java.awt.Container.dispatchEventImpl(Container.java:1609) at java.awt.Component.dispatchEvent(Component.java:3480) at java.awt.EventQueue.dispatchEvent(EventQueue.java:450) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThrea d.java:197) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread. java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136) at java.awt.EventDispatchThread.run(EventDispatchThread.java:99) |
| Sorry about the comments (or lack thereof). Anybody know whats wrong? Thanks, Josh
|
|
|
|
arielm
|
Re: Unhelpful Error
« Reply #1 on: Feb 24th, 2004, 10:20am » |
|
i can see 2 potential (and linked) problems: 1) you're instantiating "shape" before setup() instead of within setup() 2) inside the "Shape" constructor, you're drawing some stuff hth
|
Ariel Malka | www.chronotext.org
|
|
|
|