关于Exception in thread "main" java.lang.NullPointerException错误求解

clear2017 2017-10-03 08:27:22
package fddffd;

class Customer
{
private int personcode,type,money;
Customer(){}
Customer(int t1,int t2,int t3)
{
personcode=t1;
type=t2;
money=t3;
}
public int getcode()
{
return personcode;
}
public int gettype()
{
return type;
}
public int getmoney()
{
return money;
}
}
class Queue
{
Customer p[];
int size=0;
Queue()
{
int i;
for(i=0;i<100;i++)
{
p[i]=new Customer();
}
}
public void add(Customer c)
{
p[size]=c;
size++;
}
public void delete()
{
int i;
for(i=0;i<size-1;i++)
{
p[i]=p[i+1];
size--;
}
p[i]=new Customer();
}
public Customer gettop()
{
return p[0];
}
public int getsize()
{
return size;
}
}
class Bank
{
public int amount,code=0,order=1,flag=0;
Queue q1,q2;
Bank(int n)
{
amount=n;
q1=new Queue();
q2=new Queue();
}
public void newcustomer(int t1,int t2)
{
code++;
Customer c1;
c1=new Customer(code,t1,t2);
q1.add(c1);
if(flag==0)
{
flag=dealq1();
}
else
{
dealq2();
flag=0;
}
}
public int dealq1()
{
if(q1.p[0].gettype()==1)
{
if(q1.p[0].getmoney()>amount)
{
Customer c2;
c2=q1.gettop();
q1.delete();
q2.add(c2);
return 0;
}
else
{
amount=amount-q1.p[0].getmoney();
display(q1);
order++;
q1.delete();
return 0;
}
}
else
{
amount=amount+q1.p[0].getmoney();
display(q1);
q1.delete();
return 1;
}
}
public void dealq2()
{
if(q2.p[0].getmoney()<amount)
{
Customer c2;
c2=q2.gettop();
q2.delete();
q2.add(c2);
}
else
{
amount=amount-q2.p[0].getmoney();
display(q2);
order++;
q2.delete();
}
}
public void display(Queue q)
{
System.out.println("我是第"+order+"个被处理的,我的个人信息为:编号为:"+q.p[0].getcode()+";业务类型为"+q.p[0].gettype()+";金额为:"+q.p[0].getmoney());
}
}
public class Test
{
public static void main(String[] args)
{
int i;
Bank b=new Bank(1000);
int test1[]={1,1,1,2,2};
int test2[]={700,500,200,300,400};
for(i=0;i<5;i++)
{
b.newcustomer(test1[i], test2[i]);
}
}
}

错误提示:Exception in thread "main" java.lang.NullPointerException
at fddffd.Queue.<init>(Test.java:35)
at fddffd.Bank.<init>(Test.java:69)
at fddffd.Test.main(Test.java:144)
...全文
202 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一个治疗术 2017-10-11
  • 打赏
  • 举报
回复
at fddffd.Test.main(Test.java:144)
末流码农 2017-10-11
  • 打赏
  • 举报
回复
我觉得这种空指针异常最好是自己解决。。毕竟控制台信息都给你打印出来了,也不是啥难的问题,如果是新手,自己去摸索解决,对自己成长帮助还是挺大的

50,545

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧