This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes java.lang.NumberFormatException: null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "java.lang.NumberFormatException: null" Watch "java.lang.NumberFormatException: null" New topic
Author

java.lang.NumberFormatException: null

Azeem Rathore
Ranch Hand

Joined: Jun 26, 2013
Posts: 30
hi I AM NEW to programming
i have form which contains 103 textfields and it is filled from database values
now i want to insert the new record when user press new button all field become empty
when i enter data in the textfields and press save button it gives me this exception

Aug 01, 2013 11:42:14 PM hr.forms.df jButton7ActionPerformed
SEVERE: null
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.parseInt(Integer.java:527)
at hr.forms.df.NewEmployees(df.java:2846)
at hr.forms.df.jButton7ActionPerformed(df.java:2768)
at hr.forms.df.access$600(df.java:25)
at hr.forms.df$7.actionPerformed(df.java:2296)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)



the text field could be pempty i have made check if textfield.gettext is empty the set null and insert null
please tell me how to cope with this and tell me what is actual issue how to solve it
regards

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

From the stack trace, we can tell that you are calling Integet.parseInt() in the actionListener of the button - but, you are passing a null value. So, how and why are you passing a null value?


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
i have form which contains 103 textfields and it is filled from database values


- use JList (non_editable) or JTable, instead of bothering with unmanageble numbers of JTextField

- store Numbers (Date etc...) in JFormattedTextField or JSpinner
Azeem Rathore
Ranch Hand

Joined: Jun 26, 2013
Posts: 30
Actually i have columns in database table which can be empty if insert data and types are varchar and integers
I have made employee class and defines few integer variables an make setters getters
Reason i am using integer.parseint is
When i take values from textfield and send to integer setter it gives error like required int found string
So i use im using integer.parseInt function
Example is

So what i want is when adding new record if i left any field empty and press add new record button it should set values to null or empty and add record
this is whati am doing to handle this

Hope i make you understand
Please help
Regards
Azeem Rathore
Ranch Hand

Joined: Jun 26, 2013
Posts: 30
i am just beginner may be i am handling this thing wrong so guide me please
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

You should have the empCode as Integer rather than just int. Then you can set null by calling setEmpCode(null);
Azeem Rathore
Ranch Hand

Joined: Jun 26, 2013
Posts: 30
Hi Ranganathan
thanks for the help i have changed all the variables from int to Integer now when i press add record button it giives me error message ORA-01722: invalid number
i have search internet about this issue they say this errors occurs when we convert strings into Integer so i assume i have same old issue i am passing null to integer this is why error occurs i am assuming this may be i am wrong
please help and thanks again

Regards
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

Did you look up on the Oracle help pages to find out what 'ORA-01722: invalid number' is? I mean they would have provided more details.

Also, you haven't said how you persist data. Do you use plain JDBC? JPA? Hibernate?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NumberFormatException: null