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个回答
展开全部
java.lang.NullPointerException指的是空指针
thread "main" java.lang.NullPointerException意思是你的main线程出现了引用空指针的异常
thread "main" java.lang.NullPointerException意思是你的main线程出现了引用空指针的异常
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
空指针的错
at Company.Add(jewel.java:13)
at jewel.main(jewel.java:87)
编译器不是告诉你13行和87有错吗。。。应该是方法有问题或者方法里面的参数有问题,你这一大堆代码看的累死,自己找找问题吧
public class jewel{
public static void main(String args[])
jewel自定义类里面写个main函数。。被你笑死,菜鸟一个我都懒的说你,还问问会不会,自己先去翻翻书吧
发现刚才争论的原因了,你至少把public class jewel{写在第一行啊。。。写在下面难道是上面的那些类都是写成单独的一个个class。。。自己书写有问题。。。
at Company.Add(jewel.java:13)
at jewel.main(jewel.java:87)
编译器不是告诉你13行和87有错吗。。。应该是方法有问题或者方法里面的参数有问题,你这一大堆代码看的累死,自己找找问题吧
public class jewel{
public static void main(String args[])
jewel自定义类里面写个main函数。。被你笑死,菜鸟一个我都懒的说你,还问问会不会,自己先去翻翻书吧
发现刚才争论的原因了,你至少把public class jewel{写在第一行啊。。。写在下面难道是上面的那些类都是写成单独的一个个class。。。自己书写有问题。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java.lang.NullPointerException:空指针异常
java在运行过程中,对象没有实例化就调用了该对象的方法或属性,会抛出空指针异常,表明该对象为null
java在运行过程中,对象没有实例化就调用了该对象的方法或属性,会抛出空指针异常,表明该对象为null
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询