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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:38:33+00:00 2026-06-03T21:38:33+00:00

I have four classes. Project Class, Student Class, ProjectFile Class and ProjectFrame JFrame. The

  • 0

I have four classes. Project Class, Student Class, ProjectFile Class and ProjectFrame JFrame.

The ProjectFrame is only for GUI and i haven’t touched that.

The Student and Project Class are constructors and i’ve coded those.

Now i’m trying to implement the ProjectFile class by reading from a text file and then storing the data to be read. I am having trouble as i’m not sure why the Instance of the Project Class isn’t storing the data. I’ve looked at my loops and i did print the variables to be sure that the loop is actually happening. It works for the first time but when i try to call the second array, it gives me a NullPointerException. So i’m assuming it’s storing the value as null but that shouldn’t be the case.

This is my ProjectFile Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DecelAssignment;

import java.io.*;

/**
 *
 * @author Zane
 */
public class ProjectFile {

    private static Project[] pJect;
    private static Student[] sDent;
    private static Project ja;
    private static BufferedReader br;

    public static void readData() {
        File inputFile = new File("projects.txt");

        try {
            br = new BufferedReader(new FileReader(inputFile));
            String s = br.readLine();
            pJect = null;
            pJect = new Project[Integer.parseInt(s)];
            //System.out.println(s);
            for (int i = 0; i < pJect.length; i++) {
                s = br.readLine();
                if (s == null) {
                    break;
                } else {
                    String sLine[] = s.split(",");
                    int count = 3;
//                    for (int i2 = 0; i2 < Integer.parseInt(sLine[3]); i2++) {
//                        sDent[i2] = new Student(sLine[count+1], sLine[count+2], sLine[count+3], sLine[count+4]);
//                        count += 4;
//                    }
                    pJect[i] = new Project(sLine[0], sLine[1], sLine[2], sDent);
                    System.out.println(pJect[1].getTitle());
                    System.out.println(sLine[0]);
                    System.out.println(i);
                }
            }

        } catch (IOException e) {

            System.out.println("I caught an IO Exception1");
        }
//        } catch (NullPointerException e) {
//            e.printStackTrace();
//            System.out.println("I caught a Null Pointer Exception!");
//
//        }
    }

//    public Project[] getProjectInfo() {
//        
//        
//        return;
//    }
    public static void main(String[] args) {    
        readData();
    }
}

This is the text file i’m reading from

3
iPhone App,EEE,John Tan,1,P109520,Kelvin Tay,DBIT,M
iPad App,DMIT,Mark Goh,3,P106286,Felicia Wong,DIT,F,P101803,Rachel Chang,DIT,F,P100036,Lewis Poh,DBIT,M
Green Living,DMIT,Audrey Lim,2,P101234,Peter Chua,DIT,M,P103287,Ng Ming Shu,DISM,F

Can someone please explain to me where i’m coding this wrongly? I can’t figure it out.

EDIT:

This is the Project Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DecelAssignment;

/**
 *
 * @author Zane
 */
public class Project {
    private String title, school, supervisor;
    private Student[] stDent;

    public Project() {
        title = "";
        school = "";
        supervisor = "";
        stDent = new Student[0];
    }

    public Student[] getStDent() {
        return stDent;
    }

    public Project(String title, String school, String supervisor, Student[] stDent) {
        this.title = title;
        this.school = school;
        this.supervisor = supervisor;
        this.stDent = stDent;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public String getSupervisor() {
        return supervisor;
    }

    public void setSupervisor(String supervisor) {
        this.supervisor = supervisor;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}
  • 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-03T21:38:35+00:00Added an answer on June 3, 2026 at 9:38 pm

    I guess your code crashes here

          System.out.println(pJect[1].getTitle());
    

    In the first loop pJect[1] will contain null which causes a crash

    You probably intend

          System.out.println(pJect[i].getTitle());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four classes. Class Person , and three more, Student , Professor ,
i have four imageviews in a linear layout in such a manner that only
I have four classes, let's call S1, S2, S3 and S4. These class are
I have got four classes A , B , C and D . Class
I have the following PHP Classes class.property.php class.location.php class.amenity.php class.category.php all four classes handles
I have four classes. Request, DerivedRequest, Handler, DerivedHandler. The Handler class has a property
I have a four classes: class A(models.Model): field1 = models.BooleanField(default = True) class Meta:
I have four components in my large project that I'm working on... Existing JPA/Hibernate
Assume i have four classes.Each class is having a button to do screen switching
I have four classes: class A {}; class B : virtual public A {};

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.