for循环中的Nullpointer异常

时间:2016-12-11 22:00:21

标签: java for-loop nullpointerexception

每次我尝试使用displayUpaidList方法时,

循环都不起作用我得到for循环的nullpointerexception请帮忙。我真的不知道这是因为adMembership方法还是因为我使用了正确的

import java.util.ArrayList;
/**
 * Write a description of class Payment here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Payment
{
    ClubCalendar calendar;
    Membership membership;
    ArrayList<Membership> memberships;

    public Payment(){
    }
    public void addMembership(Membership membership){
        memberships.add(membership);
    }

    public void  calculateFee(Membership memberships){
        double fee; 

        if(memberships.getStatus()==false)
        {
            fee=150;
            System.out.println("150 DKK pr. quater");  
        }
        else if (memberships.getAge()< 18)
        {
            fee=375;
            System.out.println("375 DKK pr. quater");
        }
        else if (memberships.getAge()>=18 && memberships.getAge() <60)
        {
            fee=550;
            System.out.println("550 DKK pr. quater");
        }
        else if (memberships.getAge()>60)
        {
            fee=412.50;
            System.out.println("412,50 DKK pr. quater");
        }

    }

     public void displayUnpaidList(){
        for(Membership membership : memberships  ){
            if (membership.getPaymentStatus()== false ) 
            {
                System.out.println(membership.getName());
            }
        }
    }

}

0 个答案:

没有答案