swing - java.lang.numberformatexception empty string java awt -


    public class customcalculator extends frame implements actionlistener{  panel jp1 = new panel(); panel jp2 = new panel(); panel jp3 = new panel(); panel jp4 = new panel(); panel jp5 = new panel(); panel center_merge = new panel();   label l2 = new label("quantity : "); textfield l2a = new textfield(20);  label l3 = new label("invoice value : "); textfield l3a = new textfield(20);  label l4 = new label("exchange rate : "); textfield l4a = new textfield(20);  label l5 = new label("costing(a) : "); textfield l5a = new textfield();  label l6 = new label("(a + 1%)(b) : "); label l6a = new label();  label l7 = new label("bcd (c) : "); label l7a = new label("");  label l8 = new label("cvd (d) : "); label l8a = new label("");  label l9 = new label("custom education cess (e) : "); label l9a = new label("");  label l10 = new label("custom sec & higher edu.cess (f) : "); label l10a = new label("");  label l11 = new label("additional duty imports (g) : "); label l11a = new label("");  label l12 = new label("total (h) : "); label l12a = new label("");  label l13 = new label("costing+total (i) : "); label l13a = new label("");  label l14 = new label("(h/quantity) (j) : "); label l14a = new label("");  label l15 = new label("4% sad (g/quantity) (k) : "); label l15a = new label("");  label l16 = new label("net costing (l) : "); label l16a = new label("");  label l17 = new label("transportation (m) : "); textfield l17a = new textfield(5);  label l18 = new label("godown rate (n) : "); textfield l18a = new textfield(5);  label l19 = new label("brokerage (o) : "); textfield l19a = new textfield(5);  label l20 = new label("actual costing (p) : "); label l20a = new label("");  label l21 = new label("small gatepass (q) : "); label l21a = new label("");  label l22 = new label("big gatepass (r) : "); label l22a = new label("");  button l2b = new button("reset"); button l3b = new button("reset"); button l4b = new button("reset");   button master_reset = new button("reset all"); button calc = new button("calculate");    public customcalculator() {     super("custom calculator");     this.setsize(800,700);      jp1.setlayout(new flowlayout());     //jp1.setborder(borderfactory.createlineborder(color.gray));      jp1.add(l2);     jp1.add(l2a);     jp1.add(l2b);      jp1.add(l3);     jp1.add(l3a);     jp1.add(l3b);      jp1.add(l4);     jp1.add(l4a);     jp1.add(l4b);      jp2.setlayout(new gridlayout(6,2));     //jp2.setborder(borderfactory.createlineborder(color.gray));      jp2.add(l5);     jp2.add(l5a);      jp2.add(l6);     jp2.add(l6a);      jp2.add(l7);     jp2.add(l7a);      jp2.add(l8);     jp2.add(l8a);      jp2.add(l9);     jp2.add(l9a);      jp2.add(l10);     jp2.add(l10a);      jp3.setlayout(new gridlayout(6,2));     //jp3.setborder(borderfactory.createlineborder(color.gray));      jp3.add(l11);     jp3.add(l11a);      jp3.add(l12);     jp3.add(l12a);      jp3.add(l13);     jp3.add(l13a);      jp3.add(l14);     jp3.add(l14a);      jp3.add(l15);     jp3.add(l15a);      jp3.add(l16);     jp3.add(l16a);      jp4.setlayout(new gridlayout(6,2));     //jp4.setborder(borderfactory.createlineborder(color.gray));      jp4.add(l17);     jp4.add(l17a);      jp4.add(l18);     jp4.add(l18a);      jp4.add(l19);     jp4.add(l19a);      jp4.add(l20);     jp4.add(l20a);      jp4.add(l21);     jp4.add(l21a);      jp4.add(l22);     jp4.add(l22a);      center_merge.setlayout(new gridlayout(1,3));     //center_merge.setborder(borderfactory.createlineborder(color.gray));     center_merge.add(jp2);     center_merge.add(jp3);     center_merge.add(jp4);      jp5.setlayout(new flowlayout());     //jp5.setborder(borderfactory.createlineborder(color.gray));     jp5.add(calc);     jp5.add(master_reset);      this.setlayout(new borderlayout());      this.add(jp1,borderlayout.north);     this.add(center_merge,borderlayout.center);     this.add(jp5,borderlayout.south);      this.addwindowlistener(new windowadapter(){            public void windowclosing(windowevent we)         {             system.exit(0);         }     });      l2b.addactionlistener(this);     l3b.addactionlistener(this);     l4b.addactionlistener(this);     calc.addactionlistener(this);     master_reset.addactionlistener(this);      this.setvisible(true);  }   public static void main(string[] args) {     new customcalculator();  }   @override public void actionperformed(actionevent ae) {     double quantity = 0;     double invoice_value = 0;     double exchange_rate = 0;     double a=0;     double b=0;     double c=0;     double d=0;     double e=0;     double f=0;     double g=0;     double h=0;     double i=0;     double j=0;     double k=0;     double l=0;     double m = 0;     double n = 0;     double o=0;     double p=0;     double q=0;     double r=0;  try {     quantity = double.parsedouble(l2a.gettext());     invoice_value = double.parsedouble(l3a.gettext());     exchange_rate = double.parsedouble(l4a.gettext());     m = double.parsedouble(l17a.gettext());     n = double.parsedouble(l18a.gettext());     o = double.parsedouble(l19a.gettext());      = invoice_value*exchange_rate;     b = a+(0.01*a);     c = 0.075*b;     d = 0.12*(b+c);     e = 0.02*(c+d);     f = 0.01*(c+d);     g = 0.04*(b+c+d+e+f);     h = c+d+e+f+g;     = a+h;     j = h/quantity;     k = g/quantity;     l = j-k;     p = l+m+n+o;     q = (0.12*b)/quantity;     r = q+k;        if(ae.getactioncommand().equals("calc"))       {          l5a.settext(string.valueof(a));         l6a.settext(string.valueof(b));         l7a.settext(string.valueof(c));         l8a.settext(string.valueof(d));         l9a.settext(string.valueof(e));         l10a.settext(string.valueof(f));          l11a.settext(string.valueof(g));         l12a.settext(string.valueof(h));         l13a.settext(string.valueof(i));         l14a.settext(string.valueof(j));         l15a.settext(string.valueof(k));         l16a.settext(string.valueof(l));         l20a.settext(string.valueof(p));         l21a.settext(string.valueof(q));         l22a.settext(string.valueof(r));                }     else if(ae.getactioncommand().equals("master_reset"))       {             l5a.settext("");             l2a.settext("");             l3a.settext("");             l4a.settext("");     }     }     catch (exception ex)     {         l5a.settext(ex.tostring());         // l3a.settext(ex.tostring());     }      }  } 

after click calculate button (button calc) calculated values not appear in respective labels , exception shown saying java.lang.numberformatexception: empty string. not able figure out solution. please help.

the line exchange_rate = double.parsedouble(l4a.gettext()); gives exception, because there no value in l4a , trying parse double value, try printing exception in catch clause.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -