Saturday, 15 March 2014

java - NumberFormatException while using JFrame -



java - NumberFormatException while using JFrame -

the code supposed order , cost , save them in respective arraylists.

public class setmenu0{ private double price; private int size; private string output; private string priceoutput; string next; jtextfield orderin; jtextfield pricein; private jframe orderinput; jpanel txtfldpanel; jpanel btnpanel; arraylist orderlist = new arraylist<string>(); arraylist pricelist = new arraylist<double>(); public setmenu0() { orderinput = new jframe(); orderinput.settitle("input order , price"); orderinput.setsize(200,350); orderinput.getcontentpane(); orderinput.setlayout(new borderlayout()); orderinput.setdefaultcloseoperation(jframe.exit_on_close); jpanel txtfldpanel = new jpanel(); orderin = new jtextfield(10); pricein = new jtextfield(5); txtfldpanel.add(orderin); txtfldpanel.add(pricein); jpanel btnpanel = new jpanel(); jbutton addbtn = new jbutton("add"); btnpanel.add(addbtn); addbtn.addactionlistener(new buttonlistener()); addbtn.setactioncommand("add"); jbutton fnshbtn = new jbutton("finish"); btnpanel.add(fnshbtn); addbtn.addactionlistener(new buttonlistener()); fnshbtn.setactioncommand("fnsh"); size = orderlist.size(); container cont = orderinput.getcontentpane(); cont.add(txtfldpanel,borderlayout.north); cont.add(btnpanel,borderlayout.south); orderinput.pack(); } private class buttonlistener implements actionlistener { public void actionperformed(actionevent e) { string actionenter = e.getactioncommand(); if(actionenter.equals("add")) { orderlist.add(orderin.gettext()); pricelist.add(double.parsedouble(pricein.gettext())); orderin.settext(""); pricein.settext(""); } else if(actionenter.equals("fnsh")) { orderinput.dispose(); } } } public jframe getframe() { homecoming orderinput; } public arraylist getord() { homecoming orderlist; } public arraylist getpri() { homecoming pricelist; } public int getsize() { homecoming size; } }

when press add together button shows numberformatexception. why this? add together rest of code main why not saving in arraylist?

this error: java.lang.numberformatexception: input string: "" @ java.lang.numberformatexception.forinputstring(unknown source) @ java.lang.integer.parseint(unknown source) @ java.lang.integer.parseint(unknown source) @ com.howtodoinjava.demo.poi.setmenu0$buttonlistener.actionperformed(setmenu0.java:84) @ javax.swing.abstractbutton.fireactionperformed(unknown source) @ javax.swing.abstractbutton$handler.actionperformed(unknown source) @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @ javax.swing.defaultbuttonmodel.setpressed(unknown source) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$400(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)

it's due line:

pricelist.add(double.parsedouble(pricein.gettext()));

you want create sure pricein text field contains number before seek parse text.

java jframe actionlistener jtextfield numberformatexception

No comments:

Post a Comment