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

  • SEARCH
  • Home
  • 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 8262751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:51:38+00:00 2026-06-08T03:51:38+00:00

import java.io.*; class AccountInfo { private String lastName; private String firstName; private int age;

  • 0
    import java.io.*;
    class AccountInfo {

    private String lastName;
    private String firstName;
    private int age;
    private float accountBalance;
    protected AccountInfo(final String last,final String first,final int ag,final float balance) throws IOException{

        lastName=last;
        firstName=first;
        age=ag;
        accountBalance=balance;
    }
    public void saveState(final OutputStream stream){try{

        OutputStreamWriter osw=new OutputStreamWriter(stream);
        BufferedWriter bw=new BufferedWriter(osw);
        bw.write(lastName);
        bw.newLine();
        bw.write(firstName);
        bw.write(age);
        bw.write(Float.toString(accountBalance));
        bw.close();}
        catch(IOException e){
            System.out.println (e);
        }
    } 
    public void restoreState(final InputStream stream)throws IOException{
        try{


            InputStreamReader isr=new InputStreamReader(stream);
            BufferedReader br=new BufferedReader(isr);
            lastName=br.readLine();
            firstName=br.readLine();
            age=Integer.parseInt(br.readLine());
            accountBalance=Float.parseFloat(br.readLine());
            br.close();}
            catch(IOException e){
                System.out.println (e);
        }

    }

}
    class accounto{
        public static void main (String[] args) {try{



            AccountInfo obj=new AccountInfo("chaturvedi","aayush",18,18);
            FileInputStream fis=new FileInputStream("Account.txt");
            FileOutputStream fos=new FileOutputStream("Account,txt");
            obj.saveState(fos);
            obj.restoreState(fis);}
            catch(IOException e){
                System.out.println (e);
        }
    }
}

im getting the following error: Exception in thread “main” java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.parseInt(Integer.java:527)
at AccountInfo.restoreState(accounto.java:43)
at accounto.main(accounto.java:60)

  • 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-06-08T03:51:40+00:00Added an answer on June 8, 2026 at 3:51 am

    This is your code:

    BufferedReader br=new BufferedReader(isr);
    //...
    age=Integer.parseInt(br.readLine());
    

    And here is the documentation of BufferedReader.readLine() (bold mine):

    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

    In fact, you never really check whether EOF was reached. Can you be that certain about your input (turns out you can’t).

    Also for Integer.parseInt():

    Throws:

    NumberFormatException – if the string does not contain a parsable integer.

    null is hardly a "parsable integer". The simplest solution is to check your input and handle errors somehow:

    String ageStr = br.readLine();
    if(ageStr != null) {
      age = Integer.parseInt(br.readLine())
    } else {
      //decide what to do when end of file
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have three classes : CustomerData.java import java.util.Date; public class CustomerData { private String
i have a domain class like package trip.side import java.text.SimpleDateFormat class HotelStay { String
Here's the relevant part of the Dice class: import java.util.*; class Dice { String
import java.util.Scanner; public class CourseSplitter { public static void main(String args[]){ Scanner keyboard =
import java.lang.System; public class Splitter{ public static void main(String args[]){ String path_separator = Path
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
I have this Java class class Dog { private String name; public Dog() {
So given the following java class: class Outer { private int x; public Outer(int
import java.nio.charset.Charsets in my class UriCodec.java,but when i use javac(jdk6) compile this class error.
// Here's my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;

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.