• Register
0 votes
21 views

I am new to java programming . I was practicing some code about string. I wrote a code:

public class NewClass {
    
    
    public static void main(String[] args) {
        int  m ;
        String s ;
        
        
        m = Integer.parseInt(ss);
        
        System.out.println(ss);
        
        
    }
    
}

But that gives me some error:

Exception in thread "main" java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:542)
	at java.lang.Integer.parseInt(Integer.java:615)
	at javastackoverflow.NewClass.main(NewClass.java:13)
C:\Users\Hp\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

What is the problem in my code and why am I getting this error?

Can anyone help me out?

6.1k points

Please log in or register to answer this question.

1 Answer

0 votes
Integer.parseInt(String s) is the most common way of converting numbers represented by String variables to int (primitive) in Java. The example below shows how to use the parseInt(...) method to convert a Str
public static void main(String[] args) {
        String s = "25";
        int m = Integer.parseInt(s);
        System.out.println(m);
}

 

35k points