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 & HelpPrograms › I get this error in my program
Page Index Toggle Pages: 1
I get this error in my program (Read 758 times)
I get this error in my program
Mar 2nd, 2007, 9:41pm
 
ControlP5 0.1.1 infos, comments, questions at http://www.sojamo.de/controlP5


ERROR. an error occured while forwarding a Controller value
to a method in your program. please check your code for any
possible errors that might occur in this method .
e.g. check for casting errors, possible nullpointers, array overflows ... .
method: printText
exception:  java.lang.reflect.InvocationTargetException

/**
* controlP5texfield by andreas schlegel
* textfield is a controller for single line text input.
* controlP5 website at http://www.sojamo.de/controlP5
*/
import controlP5.*;

ControlP5 controlP5;

int myColorBackground = color(0,0,0);

/* the textValue field will be used as unique name for a textfield
* controller below, hence it will be automatically updated by controlP5
* if changes are made to the controller. mkae sure the field is
* public so that the automatic update will work and now security exception
* will occur.
*/
public String textValue = "";
public String name ="";
public String email ="";
public String phone = "";

public PrintWriter output;
PFont myFont;
PImage e;




void setup() {
 size(400,600);
 controlP5 = new ControlP5(this);
 controlP5.addTextfield("name",100,80,200,20);
 controlP5.addTextfield("email",100,120,200,20);
 controlP5.addTextfield("phone",100,160,200,20);
 controlP5.addBang("printText",100,200,100,20);
 output = createWriter("info.txt"); // Create a new file in the sketch directory
}

void draw() {

 background(myColorBackground);
 e = loadImage("enter.jpg");
 image(e, 0, 0);

}

/* controlP5 checks each controller's unique name when created.
* if the name equals a method or field in your sketch, then controlP5
* will forward events triggered by a controller to its applicable
* method or field.
*/
/*
void texts(String theText) {
 println("texts : "+theText);
}
*/

void printText() {
/*  println("Name: "+name);
 println("Email: "+email);
 println("Phone:"+phone);
*/
 output.println(name);// Write to the file
 output.println(email);// Write to the file  
 output.println(phone);// Write to the file
 output.flush(); // Writes the remaining data to the file
 output.close(); // Finishes the file

}

I am new to processing but have a good understanding of programming but I havent gotten this error before.  Can anyone help me?
Re: I get this error in my program
Reply #1 - Mar 3rd, 2007, 3:41am
 
hi,
the library executes all controllers at the beginning by default. so when printText() is called in this case, output isnt created yet. just put
Code:

output = createWriter("info.txt");

before you create controlP5


andi
Page Index Toggle Pages: 1