When i access a class variable by array of objects it shows NullPointerException at the commented line
<pre><code>import java.io.*;
class hostel
{
    public byte ch;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public short rollno=0;
    private byte year;
    private int mfee,refee,cafee;
    protected String name=" ";
    private String branch,gen;
    hostel()throws Exception
    {

            System.out.println("\t\t\tHOSTEL MANAGEMENT SOFTWARE");
            System.out.println("\n\n\t1.New Registration\n\t2.Login\n\t3.Exit");
            System.out.println("\n\n\tEnter your choice");
            ch=Byte.parseByte(br.readLine());
    }
    public void stu_details()throws Exception
    {
        System.out.println("\t\t"+"*__STUDENT DETAILS__*");
        System.out.println("Enter Students RollNo: ");
        rollno=Short.parseShort(br.readLine());
        System.out.println("Enter Students Name: ");
        name=br.readLine();
        System.out.println("Enter Branch name: ");  
        branch=br.readLine();
        System.out.println("Year: ");
        year=Byte.parseByte(br.readLine());
        System.out.println("Gender: ");
        gen=br.readLine();
    }
    public void hos_fees()throws Exception
    {
        System.out.println("\t\t"+"*__FEE DETAILS__*");
        System.out.println("Room Rent: ");
        refee=Integer.parseInt(br.readLine());
        System.out.println("Mess fee: ");
        mfee=Integer.parseInt(br.readLine());
        System.out.println("Caution fee(1 time): ");
        cafee=Integer.parseInt(br.readLine());
    }
    public void putdetails()
    {
        System.out.println("\t\t\tHOSTEL MANAGEMENT SOFTWARE");         
        System.out.println("\n\nRoll No: " + rollno);
        System.out.println("Name: " + name);
        System.out.println("Gender: " + gen);
        System.out.println("Branch: " + branch);
        System.out.println("Year: " + year);
        System.out.println("\n\n\t\t"+"*__FEE DETAILS__*");
        System.out.println("Room Rent: " + refee);
        System.out.println("Mess fee: " + mfee);
        System.out.println("Caution Deposit: " + cafee);


    }   

    public static void main(String args[])throws Exception
    {   

        int n,opt,k=0,i=0;
        hostel [] stu = new hostel[10];
        hostel stud = new hostel();
        opt=stud.ch;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for(;;)
        {
            switch(opt)
            {
                case 1:
                    System.out.println("\t\t\tHOSTEL MANAGEMENT SOFTWARE"); 
                    for(i=0;i&lt;10;i++)
                    {
                        if((stu[i].name)==null)
                        {
                        break;
                        }
                    stu[i].stu_details();
                    stu[i].hos_fees();
                    }
                    break;
                case 2:
                    System.out.println("\t\t\tHOSTEL MANAGEMENT SOFTWARE");

                    System.out.println("Enter Student's Roll No");
                    n=Integer.parseInt(br.readLine());
                    for(i=0;i&lt;10;i++)
                    {
        //              if(n==stu[i].rollno)
                        {
                            k++;
                            break;
                        }
                    }
                    if(k==1)
                    {
        //              stu[n].putdetails();
                    }
                    else
                    System.out.println("Enter a valid Roll no");
                    break;
                case 3: System.exit(0);
            }
        }

    }
}
</code></pre>
