Sunday 26 May 2019

Java: What is NumberFormatException?


NumberFormatException thrown while application trying to convert a string to one of the numeric types, but that the string does not have the appropriate format.

App.java
package com.sample.app;

import java.io.IOException;

public class App {

  public static void main(String args[]) throws IOException {
    String str = "Abrakadabra";
    int i = Integer.parseInt(str);

    System.out.println("i : "+ i);
  }

}

Run App.java, you will get NumberFormatException.

Exception in thread "main" java.lang.NumberFormatException: For input string: "Abrakadavra"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:580)
  at java.lang.Integer.parseInt(Integer.java:615)

  at com.sample.app.App.main(App.java:9)


You may like

No comments:

Post a Comment