Java NullPointerException In the constructor's class

Posted by AndreaF on Stack Overflow See other posts from Stack Overflow or by AndreaF
Published on 2012-03-25T11:22:38Z Indexed on 2012/03/25 11:30 UTC
Read the original article Hit count: 224

Filed under:
|

I have made a Java class where I have defined a constructor and some methods but I get a NullPointer Exception, and I don't know how I could fix It.

public class Job {

    String idJob;
    int time;
    int timeRun;
    Job j1;

    List<Job> startBeforeStart;
    List<Job> restricted;

    Job(String idJob, int time){
        this.idJob=idJob;
        this.time=time;

    }


    public boolean isRestricted() {
        return restricted.size() != 0;
    }

    public void startsBeforeStartOf(Job job){
            startBeforeStart.add(job);
            job.restricted.add(this);
    }

    public void startsAfterStartOf(Job job){
            job.startsBeforeStartOf(this);
    }

    public void checkRestrictions(){

        if (!isRestricted()){
            System.out.println("+\n");
            }
        else{
            Iterator<Job> itR = restricted.iterator();
            while(itR.hasNext()){
                 Job j1 = itR.next();
                 if(time>timeRun){
                     System.out.println("-\n");
                     time--;
                 }
                 else {
                     restricted.remove(j1);
                 }
            }
        }
    }






    @Override
    public boolean equals(Object obj) {
        return obj instanceof Job && ((Job) obj).idJob.equals(idJob);
    }



     public void run() {
         timeRun++;
     }



}

PS Looking in a forum a user says that to fix the error I should make an ArrayList inside the constructor (without modify the received parameters that should remain String id and int time), but I haven't understand what He mean.

© Stack Overflow or respective owner

Related posts about java

Related posts about nullpointerexception