日期:2014-05-20  浏览次数:20696 次

JAVA中报错---No enclosing instance of type……
大家好,我是一个JAVA的初学者,希望哪为朋友能给我讲一下具体错在哪~~非常感谢!!


//构造函数
public   Person(String   f,String   l,int   c,int   d,int   o,int   r)
    {
      firstName=f;
      lastName=l;
      content=c;
      delivery=d;
      organization=o;
      rank=r;
    }

………………

Person   debateGroup[]=new   Person[size];
for(int   i=0;i <size;i++)
      {

        //从键盘输入firstName,lastName,content,delivery,organization,rank,并将后面四个转换成int类型
      ………………
      //用构造函数给对象赋值
      debateGroup[i]=new   Person(firstName,lastName,content,delivery,organization,rank);  
      }

最后报错信息为:(Donna是类名)
No   enclosing   instance   of   type   Donna   is   accessible.   Must   qualify   the   allocation   with   an   enclosing  
instance   of   type   Donna   (e.g.   x.new   A()   where   x   is   an   instance   of   Donna).

------解决方案--------------------
你得Donna类呢?
错误的信息是指你要先创建一个Donnal类的实例。
------解决方案--------------------
新建一个donna的一个实例就可以了,在你的文件中加入
Donna d = new Donna();