wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to use parseInt() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use parseInt()" Watch "how to use parseInt()" New topic
Author

how to use parseInt()

Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
where should i equate the Interger.parseInt();? :roll: :roll: :roll:


jherald
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
Hi Jherald,
Can you rephrase your question or make it more detail?
Ramaswamy Narayanan
Greenhorn

Joined: Jan 19, 2005
Posts: 24
In java, we can change any data type to string by adding with a string.
if i have the String
int i=0;
String str=""+i;

now the value of i is 10 and the value of str also i.
we can perform mathematical operation on i and not str eventhouth str is an integer.
so we have to convert the str to an integer format.
for that
int x=Integer.parseInt(str);
then the x contains integer variable.

The solution is
from the string having the integer value, we can get integer using the parseInt funtion.
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
thnx for the reply

when i use this:

int num = Integer.parseInt(text2);

the error generated was:

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

java.lang.NumberFormatException: For input string: " "

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)

at java.lang.Integer.parseInt(Integer.java)

at java.lang.Integer.parseInt(Integer.java:518)

at mypackage.Calculator$16.actionPerformed(Calculator.java:183)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Component.dispatchEvent(Component.java)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:458)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Process exited with exit code 0.
Ramaswamy Narayanan
Greenhorn

Joined: Jan 19, 2005
Posts: 24
i need extra information about the 'text2' variable.
is it a String variable contains integer data?
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
static String text2 = new String();
Calculator.text2 = Calculator.txt.getText();
int num = Integer.parseInt(text2);
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 164
From the error code we can see that variable text2 contains only a space. So it can't be converted into integer.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Jherald Lacambra:
int num = Integer.parseInt(text2);

the error generated was:

java.lang.NumberFormatException: For input string: " "
This is telling you that the String text2 contains a single space and that's it. This is not a valid integer. To handle bad input, you can use a try/catch block.
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
my string has not yet been initialize till my button is pressed so how can it contain space?..
is there some other possibility for the errors?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Can you post more of the surrounding code? How about printing out the value before converting it into an int (put |s or "s around it so you can see if it's empty or null or a space).

Um, why are you converting it before it has a value? That will always fail. Also, if it were null (uninitialized), I believe parseInt will throw a NullPointerException (read the JavaDocs to be sure).
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
thanks for your reply.. but i manage a different way of solving it
 
wood burning stoves
 
subject: how to use parseInt()
 
Similar Threads
Happy Diwali
Anti-US and pro-US
Where Look Each Week To Find Out Forum to Win Books?
recommendation for moderator...
[political] Clear me on WMD arithmetics