• Register
0 votes
18 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?

10 7 2
6,060 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);
}

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 20 views
20 views
Problem: I have done: cut -f FR07937945--FR07937944_gridss.vcf.gridss_RPostProcess.bedpe and confirmed that all of the second column (QUAL) are digits. Some are integers, but most are floats. Since line 387 of Event.java is: int p1 = Integer.parseInt(bits[1]); I guess there is an issue ... floats in the QUAL col, or is it that our file isn't a bedpe file, or is it that this is an error in clove?
asked Mar 23, 2020 LizzyM 6.1k points
0 votes
1 answer 17 views
17 views
Problem: Hello! I just started learning programming in Java with no prior knowledge of any other programming language. Today I attempted a quiz in which there was a question that asked me to declare a string variable and name it as ‘title’. I attempted the ... follows: string title; I have not worked with strings alot. So want to know whether my answer is correct or not? Thanks!
asked Feb 25 Code Learner 9.2k points
0 votes
1 answer 31 views
31 views
I need to know how to print all palindrome permutations of a string in Java.
asked Oct 4, 2020 Daniel Anderson 4k points
0 votes
1 answer 13 views
13 views
I need to know how to remove the first cgaracter of a string in Java.
asked Sep 25, 2020 Daniel Anderson 4k points
0 votes
1 answer 15 views
0 votes
1 answer 4 views
4 views
Problem: Hi there! I am a beginner. I have got to initialize a two-dimensional string array with some string values and then print the values stored in it. I have worked with single-dimensional arrays in Java, but have very little knowledge regarding 2D arrays. Can anyone here please provide me the code with detailed explanations and comments? I would be grateful. Thanks!
asked Mar 21 Code Learner 9.2k points
0 votes
1 answer 25 views
25 views
Problem: Hi there! I just got an assignment in which I had to remove the first and last character from a string in Java. I did the task using substrings. I want to know what the simplest way is to do so? Also, mention other alternatives to using the substring method. Thanks!
asked Jan 8 Code Learner 9.2k points
0 votes
1 answer 8 views
8 views
I need to know how to print duplicate characters from string in Java.
asked Oct 3, 2020 Daniel Anderson 4k points
0 votes
1 answer 20 views
20 views
I am having problem or facing the issue removing last character from string in JavaScript.
asked Sep 29, 2020 Daniel Anderson 4k points
0 votes
1 answer 18 views
18 views
I am finding the answers in several blog for removing particular character from string in java.
asked Sep 29, 2020 Daniel Anderson 4k points