Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6758825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:51:02+00:00 2026-05-26T13:51:02+00:00

Following is a snippet that throws java.lang.NullPointerException . else if(jRadioButton2.isSelected()) { // chrome selected

  • 0

Following is a snippet that throws java.lang.NullPointerException.

else if(jRadioButton2.isSelected()) {
             // chrome selected
             String chrome_count_S="0";
             int chrome_count_I=0;
             FileWriter writer = new FileWriter("D:\\UnderTest\\MyFirstPoll\\build\\classes\\poll_count\\Chrome.txt");
             FileReader reader = new FileReader("D:\\UnderTest\\MyFirstPoll\\build\\classes\\poll_count\\Chrome.txt");
             BufferedReader br = new BufferedReader(reader);
             while((chrome_count_S = br.readLine()) != null) {
                  chrome_count_I = Integer.parseInt(chrome_count_S);
                  chrome_count_I++;
                  chrome_count_S = Integer.toString(chrome_count_I);
             }
             writer.write(chrome_count_S);
             writer.close();

When this snippet is encountered NullPointerException is thrown. If I replace the argument of writer.write(chrome_count_S); to writer.write("chrome_count_S"); I.E. a String, I don’t get any exception. Otherwise why do I get the exception when I have initialized the string chrome_count_S?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:51:03+00:00Added an answer on May 26, 2026 at 1:51 pm

    The while loop stops when the readline() is null and writes the current value to the variable chrome_count_S.

    while((chrome_count_S = br.readLine()) != null)
    

    So chrome_count_S is be null after the loop and at the the write command.

    === UPDATE ===

    Remove the chrome_count_S row in the loop and take the value from the chrome_count_I during writing:

    while((chrome_count_S = br.readLine()) != null) {
        chrome_count_I = Integer.parseInt(chrome_count_S);
        chrome_count_I++;
    }
    writer.write(Integer.toString(chrome_count_I));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code snippet that i use to compile class at the run
How can I make sure in the following code snippet that IDataReader is disposed
I have the following snippet of code that's generating the Use new keyword if
I had the following line snippet of code that searches for a propery of
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I have a simple xml document that looks like the following snippet. I need
Take a look that the following code snippet: A a = null try {
I have the following snippet of java code: final Class<?> junitCoreClass = AccessController.doPrivileged( new
The following simple Java program appears to display the string Hello World through the
I have the following code snippet: class Cert { public static void main(String[] args)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.