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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:07:19+00:00 2026-06-03T04:07:19+00:00

I have two java classes. Schedule is the main class that uses an array

  • 0

I have two java classes. Schedule is the main class that uses an array of Jobs called deadline. I’m having problems putting anything in array. I have a for loop that reads data from a text file (it works fine) and inserts certain data into deadline. I not successfully creating deadline because whenever I want to start inserting into the array I get a NullPointerException. (The code below the ... obviously isn’t what I actually coded, but it is still the same situation.)

It has been a while since I’ve coded in Java, so I might be just overlooking something simple, but I’m not really sure what it could be… Thanks for any help you can give.

public class Schedule {

    private Job []deadline;
    Schedule (int n){
        Job[] deadline = new Job[n];
    }

    ...
        int n = 7;
        Schedule schedule = new Schedule(n);

        deadline[0] = new Job("A",3,40); // This line won't compile. NullPointerException
}


public class Job {

    private String name;
    private int deadline;
    private int profit;

    Job(String n, int d, int p){
        name = n;
        deadline = d;
        profit = p;
    }

}
  • 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-03T04:07:21+00:00Added an answer on June 3, 2026 at 4:07 am

    You are shadowing deadline in your constructor, so you don’t initialize the class member deadline, but the local one. Change it to:

        private Job []deadline;
        Schedule (int n){
            deadline = new Job[n];
        // ^^ note - no Job[] here
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Java classes: B, which extends another class A, as follows :
I have two java classes called Reader and Worker. Reader reads strings from a
I have two Java-Classes as follows: public class MyClass { ... } public class
I have written two simple Java classes (one of them containing main(), and the
Actually I have two java classes of which one is an activity class. Now
In Java I have two classes: Class A { public String ID; public Object
Does it impact memory if I have two Java classes that have native calls
I have the following two classes: import java.io.*; import java.util.*; public class User {
I have two Java class hierarchies that share a common ancestor and implement a
I'm making a shopping list mobile application (Java ME) and i have two classes;

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.