Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我通过对象数组访问类变量时,它在注释行显示NullPointerException import java.io.*; 班级宿舍 { 公共字节ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 公共短滚号=0; 私人字节年; 私人int mfee、refee、cafee; 受保护字符串名称=”; 私人字符串分支,gen; hotel()抛出异常 { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n\t1.New Registration\n\t2.Login\n\t3.Exit”); System.out.println(“\n\n\t请选择”); ch=Byte.parseByte(br.readLine()); } public void stu_details()引发异常 { System.out.println(“\t\t”+“*\u学生详细信息””; System.out.println(“输入学生卷号:”); rollno=Short.parseShort(br.readLine()); System.out.println(“输入学生姓名:”); name=br.readLine(); System.out.println(“输入分支名称:”); branch=br.readLine(); 系统输出打印项次(“年:”; year=Byte.parseByte(br.readLine()); System.out.println(“性别:”); gen=br.readLine(); } 公营房屋无效居屋收费()引发例外 { System.out.println(“\t\t”+“*\u费用明细””; System.out.println(“房间租金:”); refee=Integer.parseInt(br.readLine()); System.out.println(“餐费:”); mfee=Integer.parseInt(br.readLine()); System.out.println(“警告费(1次):”; cafee=Integer.parseInt(br.readLine()); } 公开资料(只提供英文版本) { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n卷号:“+rollno”); System.out.println(“名称:”+Name); System.out.println(“性别:+gen”); System.out.println(“分支:+分支”); 系统输出打印项次(“年:+年); System.out.println(“\n\n\t\t”+“*\u费用明细\u*”); System.out.println(“房间租金:+refee”); 系统输出打印项次(“杂费:+mfee”); System.out.println(“保证金:+cafee”); } 公共静态void main(字符串args[])引发异常 { int n,opt,k=0,i=0; 旅舍[]stu=新旅舍[10]; 旅舍螺柱=新旅舍(); opt=stud.ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 对于(;;) { 开关(opt) { 案例1: System.out.println(“\t\t\tHOSTEL管理软件”); 对于(i=0;i_Java - Fatal编程技术网

当我通过对象数组访问类变量时,它在注释行显示NullPointerException import java.io.*; 班级宿舍 { 公共字节ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 公共短滚号=0; 私人字节年; 私人int mfee、refee、cafee; 受保护字符串名称=”; 私人字符串分支,gen; hotel()抛出异常 { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n\t1.New Registration\n\t2.Login\n\t3.Exit”); System.out.println(“\n\n\t请选择”); ch=Byte.parseByte(br.readLine()); } public void stu_details()引发异常 { System.out.println(“\t\t”+“*\u学生详细信息””; System.out.println(“输入学生卷号:”); rollno=Short.parseShort(br.readLine()); System.out.println(“输入学生姓名:”); name=br.readLine(); System.out.println(“输入分支名称:”); branch=br.readLine(); 系统输出打印项次(“年:”; year=Byte.parseByte(br.readLine()); System.out.println(“性别:”); gen=br.readLine(); } 公营房屋无效居屋收费()引发例外 { System.out.println(“\t\t”+“*\u费用明细””; System.out.println(“房间租金:”); refee=Integer.parseInt(br.readLine()); System.out.println(“餐费:”); mfee=Integer.parseInt(br.readLine()); System.out.println(“警告费(1次):”; cafee=Integer.parseInt(br.readLine()); } 公开资料(只提供英文版本) { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n卷号:“+rollno”); System.out.println(“名称:”+Name); System.out.println(“性别:+gen”); System.out.println(“分支:+分支”); 系统输出打印项次(“年:+年); System.out.println(“\n\n\t\t”+“*\u费用明细\u*”); System.out.println(“房间租金:+refee”); 系统输出打印项次(“杂费:+mfee”); System.out.println(“保证金:+cafee”); } 公共静态void main(字符串args[])引发异常 { int n,opt,k=0,i=0; 旅舍[]stu=新旅舍[10]; 旅舍螺柱=新旅舍(); opt=stud.ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 对于(;;) { 开关(opt) { 案例1: System.out.println(“\t\t\tHOSTEL管理软件”); 对于(i=0;i

当我通过对象数组访问类变量时,它在注释行显示NullPointerException import java.io.*; 班级宿舍 { 公共字节ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 公共短滚号=0; 私人字节年; 私人int mfee、refee、cafee; 受保护字符串名称=”; 私人字符串分支,gen; hotel()抛出异常 { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n\t1.New Registration\n\t2.Login\n\t3.Exit”); System.out.println(“\n\n\t请选择”); ch=Byte.parseByte(br.readLine()); } public void stu_details()引发异常 { System.out.println(“\t\t”+“*\u学生详细信息””; System.out.println(“输入学生卷号:”); rollno=Short.parseShort(br.readLine()); System.out.println(“输入学生姓名:”); name=br.readLine(); System.out.println(“输入分支名称:”); branch=br.readLine(); 系统输出打印项次(“年:”; year=Byte.parseByte(br.readLine()); System.out.println(“性别:”); gen=br.readLine(); } 公营房屋无效居屋收费()引发例外 { System.out.println(“\t\t”+“*\u费用明细””; System.out.println(“房间租金:”); refee=Integer.parseInt(br.readLine()); System.out.println(“餐费:”); mfee=Integer.parseInt(br.readLine()); System.out.println(“警告费(1次):”; cafee=Integer.parseInt(br.readLine()); } 公开资料(只提供英文版本) { System.out.println(“\t\t\tHOSTEL管理软件”); System.out.println(“\n\n卷号:“+rollno”); System.out.println(“名称:”+Name); System.out.println(“性别:+gen”); System.out.println(“分支:+分支”); 系统输出打印项次(“年:+年); System.out.println(“\n\n\t\t”+“*\u费用明细\u*”); System.out.println(“房间租金:+refee”); 系统输出打印项次(“杂费:+mfee”); System.out.println(“保证金:+cafee”); } 公共静态void main(字符串args[])引发异常 { int n,opt,k=0,i=0; 旅舍[]stu=新旅舍[10]; 旅舍螺柱=新旅舍(); opt=stud.ch; BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 对于(;;) { 开关(opt) { 案例1: System.out.println(“\t\t\tHOSTEL管理软件”); 对于(i=0;i,java,Java,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=" ";

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<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<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);
            }
        }

    }
}
数组,它只是为10
hostel
创建引用,引用
null
您需要初始化它们中的每一个

比如说

hostel [] stu = new hostel[10];
你初始化了

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<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<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);
            }
        }

    }
}
数组,它只是为10
hostel
创建引用,引用
null
您需要初始化它们中的每一个

比如说

hostel [] stu = new hostel[10];

在Java中,创建类类型的数组不会创建单个对象。因此,您需要执行以下操作:

hostel[0] = new hostel();
hostel[]stu=新旅馆[10];
对于(int i=0;i
在Java中,创建类类型的数组不会创建单个对象。因此需要执行以下操作:

hostel[0] = new hostel();
hostel[]stu=新旅馆[10];
对于(int i=0;i
首先,类应始终以大写字母开头。 第二,在你的线路上,唯一能引起NullPointerException的是当stu[i]==null


.

首先,类应始终以大写字母开头。 第二,在你的线路上,唯一能引起NullPointerException的是当stu[i]==null


.

我想你可能对collections框架感兴趣,顺便说一句。你必须告诉我们在哪里抛出NullPointerException以使我们的工作更轻松…:)我想你可能对collections框架感兴趣,顺便说一句。你必须告诉我们在哪里抛出NullPointerException以使我们的工作更轻松…:)