For input string "" error. Please help
in
Contributed Library Questions
•
2 years ago
Hi
I am getting the error - For input string: "" for the below program. Does anyone have idea why I might be getting this error? Any help appreciated.
Thanks
import interfascia.*;
IFButton go,fact,restart;
GUIController g,t,r;
PFont font;
IFTextField textfield;
int f1=0,num,ans;
String a;
void setup()
{
size(1350,700);
g = new GUIController(this);
t = new GUIController(this);
go = new IFButton ("GO!", 600, 400, 100, 20);
fact = new IFButton ("Factorial", 620, 400);
go.addActionListener(this);
fact.addActionListener(this);
textfield=new IFTextField("",620,350);
t.add(fact);
t.add(textfield);
//goLook = new IFLookAndFeel(this, IFLookAndFeel.DEFAULT);
//goLook.baseColor = color(180);
//goLook.highlightColor = color (80);
//c.setLookAndFeel(goLook);
//c.setHeight(50);
g.add (go);
r = new GUIController (this);
restart = new IFButton ("Restart", 1170, 620, 100, 20);
restart.addActionListener(this);
r.add(restart);
font=loadFont("ArialRoundedMTBold-60.vlw");
textFont(font);
t.setVisible(false);
r.setVisible(false);
}
void draw()
{
smooth();
if(f1==0)
{
fill(0);
//choice.setVisible(false);
background(70,150,20);
textSize(60);
text("Let's learn about recursion",260,300);
textSize(40);
text("In Computer Science",480,350);
//c.setVisible(false);
//for(int i=3;i<93;i++)
}
if(f1==1)
{
background(70,150,20);
stroke(0);
strokeWeight(4);
textSize(50);
text("Enter a number from 1 to 4 to find its factorial",150,300);
}
if(f1==2)
{
if(num==1)
{
background(255);
textSize(40);
text("Factorial of 1 = 1",200,350);
}
}
}
void actionPerformed (GUIEvent e)
{
if(e.getSource()==go)
{
//frameRate(5);
f1=1;
g.setVisible(false);
t.setVisible(true);
//c.setVisible(true);
r.setVisible(true);
draw();
}
if(e.getSource()==fact)
{
f1=2;
a=textfield.getValue();
//println(str);
num=Integer.parseInt(a);
t.setVisible(false);
draw();
//println(a);
}
/*if(e.getSource()==restart)
{
f1=0;
num=0;
ans=0;
t.setVisible(false);
r.setVisible(false);
g.setVisible(true);
textfield.setValue("");
draw();
}*/
}
I am getting the error - For input string: "" for the below program. Does anyone have idea why I might be getting this error? Any help appreciated.
Thanks
import interfascia.*;
IFButton go,fact,restart;
GUIController g,t,r;
PFont font;
IFTextField textfield;
int f1=0,num,ans;
String a;
void setup()
{
size(1350,700);
g = new GUIController(this);
t = new GUIController(this);
go = new IFButton ("GO!", 600, 400, 100, 20);
fact = new IFButton ("Factorial", 620, 400);
go.addActionListener(this);
fact.addActionListener(this);
textfield=new IFTextField("",620,350);
t.add(fact);
t.add(textfield);
//goLook = new IFLookAndFeel(this, IFLookAndFeel.DEFAULT);
//goLook.baseColor = color(180);
//goLook.highlightColor = color (80);
//c.setLookAndFeel(goLook);
//c.setHeight(50);
g.add (go);
r = new GUIController (this);
restart = new IFButton ("Restart", 1170, 620, 100, 20);
restart.addActionListener(this);
r.add(restart);
font=loadFont("ArialRoundedMTBold-60.vlw");
textFont(font);
t.setVisible(false);
r.setVisible(false);
}
void draw()
{
smooth();
if(f1==0)
{
fill(0);
//choice.setVisible(false);
background(70,150,20);
textSize(60);
text("Let's learn about recursion",260,300);
textSize(40);
text("In Computer Science",480,350);
//c.setVisible(false);
//for(int i=3;i<93;i++)
}
if(f1==1)
{
background(70,150,20);
stroke(0);
strokeWeight(4);
textSize(50);
text("Enter a number from 1 to 4 to find its factorial",150,300);
}
if(f1==2)
{
if(num==1)
{
background(255);
textSize(40);
text("Factorial of 1 = 1",200,350);
}
}
}
void actionPerformed (GUIEvent e)
{
if(e.getSource()==go)
{
//frameRate(5);
f1=1;
g.setVisible(false);
t.setVisible(true);
//c.setVisible(true);
r.setVisible(true);
draw();
}
if(e.getSource()==fact)
{
f1=2;
a=textfield.getValue();
//println(str);
num=Integer.parseInt(a);
t.setVisible(false);
draw();
//println(a);
}
/*if(e.getSource()==restart)
{
f1=0;
num=0;
ans=0;
t.setVisible(false);
r.setVisible(false);
g.setVisible(true);
textfield.setValue("");
draw();
}*/
}
1