Using Integer.parseInt crashes my program Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Using Integer.parseInt crashes my program without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have looked all over the internet and cannot find my out why this is happening to my program. Basically I am trying to make a TextField that that makes a string of numbers, and that string is turned into an integer and the label is changed to the number +1 Whenever I attempt to use Integer.parseInt It crashed

Here is my Code

public class dfadsfa {

    private JFrame frame;
    private JTextField textField;

     * Launch the application.
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    dfadsfa window = new dfadsfa();
                } catch (Exception e) {

     * Create the application.
    public dfadsfa() {

     * Initialize the contents of the frame.

    String Text;
    int Number = Integer.parseInt(Text); //This line Screws it up

    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);

        JLabel lblNumber = new JLabel("");
        lblNumber.setBounds(198, 181, 61, 16);

        textField = new JTextField();
        textField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Text = textField.getText();

        textField.setBounds(163, 140, 130, 26);



This is the message that shows up-

java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(
at java.lang.Integer.parseInt(
at java.lang.Integer.parseInt(
at dfadsfa.<init>(
at dfadsfa$
at java.awt.event.InvocationEvent.dispatch(
at java.awt.EventQueue.dispatchEventImpl(
at java.awt.EventQueue.access$500(
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(


Text is not initialized , So it gives a NumberFormatException. Here Integer.parseInt() method will give the NumberFormatException if the passed string does not contain a parsable integer.


String Text = "0" to solve the problem

We are here to answer your question about Using Integer.parseInt crashes my program - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji