Exception in thread "main" java.lang.NullPointerException是什么意思
classEmployee{Stringname;StringID;Stringkind;floatsalary;}classCompany{finalinti=20;s...
class Employee{
String name;
String ID;
String kind;
float salary;
}
class Company{
final int i=20;
static int p=0;
int j;
Employee employee[]=new Employee[i];
public void Add(String s,String b,String k,float a)
{ employee[p].name=s;
employee[p].ID=b;
employee[p].kind=k;
employee[p].salary=a;
p++;}
public void Delete(String s)
{ for (j=0;j<i;j++)
if (employee[j].name==s)
{employee[j].name="";
employee[j].ID="";
employee[j].kind="";
employee[j].salary=0;
break;}
}
public void Display(String s)
{ for(j=0;j<p;j++)
if(employee[j].name==s)
{System.out.println("员工"+s+"的工资为:"+employee[j].salary);
break;}
}
public void Output( )
{double sum=0;
for(j=0;j<p;j++)
sum+=employee[j].salary;
System.out.println("所有员工的工资和为:"+sum);
}
}
interface Employe{
float wages=1500;
void calculate();
}
class hours implements Employe{
int hour;
float payment;
float salary;
public hours(int h,float q)
{hour=h;
payment=q;}
public void calculate()
{salary=hour*payment;}
}
class sellor implements Employe
{float money;
float salary;
public sellor(float m){
money=m;
}
public void calculate(){
if(money<10000)
salary=wages+money*(1/10);
if(10000<=money && money<=100000)
salary=wages+money*(1/15);
if(money>100000)
salary=wages+money*(1/18);
}
}
class worker implements Employe{
float salary;
int hours;
worker(int h)
{hours=h;}
public void calculate(){
if(hours>196)
salary=wages+(hours-196)*200;
}
}
public class jewel{
public static void main(String args[])
{
Company C=new Company();
hours H1=new hours(10,200);
hours H2=new hours(10,230);
sellor S1=new sellor(5000);
sellor S2=new sellor(200000);
worker W=new worker(205);
C.Add("H1","101010120","小时工类",H1.salary);
C.Add("H2","101010121","小时工类",H2.salary);
C.Add("S1","101010125","销售员类",S1.salary);
C.Add("S2","101010130","销售员类",S2.salary);
C.Add("W","101010125","普通员工类",W.salary);
C.Display("zhangyong");
C.Output();
C.Delete("zhangyong");
C.Output();
}
}
运行后就出现Exception in thread "main" java.lang.NullPointerException
at Company.Add(jewel.java:13)
at jewel.main(jewel.java:87)
那怎么改正呢,你不会就别回答 展开
String name;
String ID;
String kind;
float salary;
}
class Company{
final int i=20;
static int p=0;
int j;
Employee employee[]=new Employee[i];
public void Add(String s,String b,String k,float a)
{ employee[p].name=s;
employee[p].ID=b;
employee[p].kind=k;
employee[p].salary=a;
p++;}
public void Delete(String s)
{ for (j=0;j<i;j++)
if (employee[j].name==s)
{employee[j].name="";
employee[j].ID="";
employee[j].kind="";
employee[j].salary=0;
break;}
}
public void Display(String s)
{ for(j=0;j<p;j++)
if(employee[j].name==s)
{System.out.println("员工"+s+"的工资为:"+employee[j].salary);
break;}
}
public void Output( )
{double sum=0;
for(j=0;j<p;j++)
sum+=employee[j].salary;
System.out.println("所有员工的工资和为:"+sum);
}
}
interface Employe{
float wages=1500;
void calculate();
}
class hours implements Employe{
int hour;
float payment;
float salary;
public hours(int h,float q)
{hour=h;
payment=q;}
public void calculate()
{salary=hour*payment;}
}
class sellor implements Employe
{float money;
float salary;
public sellor(float m){
money=m;
}
public void calculate(){
if(money<10000)
salary=wages+money*(1/10);
if(10000<=money && money<=100000)
salary=wages+money*(1/15);
if(money>100000)
salary=wages+money*(1/18);
}
}
class worker implements Employe{
float salary;
int hours;
worker(int h)
{hours=h;}
public void calculate(){
if(hours>196)
salary=wages+(hours-196)*200;
}
}
public class jewel{
public static void main(String args[])
{
Company C=new Company();
hours H1=new hours(10,200);
hours H2=new hours(10,230);
sellor S1=new sellor(5000);
sellor S2=new sellor(200000);
worker W=new worker(205);
C.Add("H1","101010120","小时工类",H1.salary);
C.Add("H2","101010121","小时工类",H2.salary);
C.Add("S1","101010125","销售员类",S1.salary);
C.Add("S2","101010130","销售员类",S2.salary);
C.Add("W","101010125","普通员工类",W.salary);
C.Display("zhangyong");
C.Output();
C.Delete("zhangyong");
C.Output();
}
}
运行后就出现Exception in thread "main" java.lang.NullPointerException
at Company.Add(jewel.java:13)
at jewel.main(jewel.java:87)
那怎么改正呢,你不会就别回答 展开
11个回答
展开全部
问题不是很清楚,从你的描述中只能看出来,所属线程报了空指针的异常。也就是说你在某一个引用了一个值是null的对象,并在这个对象上执行某一个操作。 看看出问题的行就行了,就可以看出什么东西是null了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那个地方报的空指针异常,从哪里着手,一看对象 是不是 空的 ,比如 你申明一个对象为 NULL 但是 却用 null 去点 他的 某些方法。 二 看 传过来的参数 是不是 空的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
空指针异常,比如强转和比较的时候会报异常,Integer.parseInt(null);
null.equals("some what")
null.equals("some what")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个错误信息代表你的指针(比如array或string内)溢出
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是空指针问题,你看看你的元素是不是没有初始化……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询