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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:28:27+00:00 2026-05-27T03:28:27+00:00

I have 2 files Details.java and TestDetails.java and a data file called Details.dat Details.java

  • 0

I have 2 files Details.java and TestDetails.java and a data file called Details.dat

Details.java

import java.util.Scanner;
import java.io.*;

public class Details {
    private String path;
    File myFile = new File(path);

    public void setMyFile(String path) {
        this.path = path;

    }

    public void load() throws IOException, FileNotFoundException {
        Scanner input = new Scanner(myFile);

        int numberOfMembers = input.nextInt();

        String[] members = new String[numberOfMembers];

        for (String s : members) {

            String name = input.next();

            String age = input.next();

            String qualification = input.next();

            System.out.println("The name of the family member is " + name + " the age of the family member is" + age
                    + " the qualification of the " + "family member is" + qualification);

        }
    }
}

TestDetails.java

import java.io.IOException;

public class TestDetails {

    public static void main(String[] args) {

        Details myDetails = new Details();

        myDetails.setMyFile(args[0]);

        try {
            myDetails.load();
        } catch (IOException i) {

            System.out.println(i.getMessage());
        }
    }
}

Details.dat

4

a 26 bsc

b 22 bcom

c 50 ba

d 60 bsc

Whenever i try to run the TestDetails.java file i get a NullPointerException and the stack trace points the stack trace towards the File object.

So what is the problem here? Why am i getting a NullPointerException?

p.s in the setFile() method argumnet, i pass in Details.dat in the args[0] position on the command prompt

  • 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-27T03:28:28+00:00Added an answer on May 27, 2026 at 3:28 am

    You initialize the File first and after that set the file path.
    Try to use a constructor in the Details class:

    public Details(String path)
            this.path = path;
            myFile = new File(path);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one schema file that I'm using to generate java files. I want
I am trying to upload files using Java URL class and I have found
for more details about the live id : https://accountservices.passport.net/ppnetworkhome.srf I have seen jar files
I have a html file that has invoice details I would like to know
I have files served like so: AJAX request handler -> Include file I would
In my Visual Studio 2010 project I have files with .mm file extension, that
I need to retrieve some details from a MusicXML (xml) file in Java. I
I have been looking through Adobe's File Format Specification for PSD (Photoshop files) and
I have been using JDOM library to read and write XML files through Java
I have a batch file that starts a Java process in a Windows 2003

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.