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 7955491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:43:28+00:00 2026-06-04T03:43:28+00:00

I am trying to make a program that saves a list of strings to

  • 0

I am trying to make a program that saves a list of strings to a file and then reads them into an arraylist. Here is my current code.

ObjectInputStream input = null;

    try {
        input = new ObjectInputStream(new FileInputStream("friends.txt"));
    } catch (FileNotFoundException e) {
        File f = new File("friends.txt");
        try {
            f.createNewFile();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String obj;

    try {
        while ((obj = (String)input.readObject()) != null) {
            friendly.add(obj);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

This returns a null pointer exception. I am not quite sure what is going wrong here.

  • 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-04T03:43:29+00:00Added an answer on June 4, 2026 at 3:43 am

    Well, for one thing, if the file doesn’t exist, ‘input’ will be null.

    I’m not quite sure what the rationale is for handling the case of the file not existing in the way that you do– why not just test for the existence via File.exists() and only perform the opening and reading if it exists?

    Other than that, as another commentator has said, provide a stack trace for a start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a program that reads the value at a certain address.
I have been trying, in vain, to make a program that reads text out
I am trying to make a program that loads and image and then splits
i'm trying to make a program that inserts data into specific places in existing
I am trying to make a program that when a usb is plugged into
I'm trying to make a program that read a file line by line and
I am trying to make a program that automatically corrects the perspective of a
A am trying to make a program that takes a signal from one class
I am trying to make a program that will find similar images from a
Hey, I am trying to make a program that minimises any program to the

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.