ExecutiveCollection.exObjects 没有new出来

解决方案 »

  1.   

    CustomerCareExecutive exObjects[];
    exObjects[]这个对象数组没有实例化!
      

  2.   

    CustomerCareExecutive exObjects[] = new CustomerCareExecutive[3];
      

  3.   

    CustomerCareExecutive exObjects[] = new CustomerCareExecutive[3];
      

  4.   

    exObjects[0].rating=Integer.parseInt("30+40");这一句也有问题,exObjects.rating值肯定不会是70,而且这一句要产生异常。Integer.parseInt(String s)其中s的各个组成部分必须全部是十进制数字,但第一位可以是-表示负数。exObjects[0].rating=Integer.parseInt("70");应该就没问题了。还有就是楼上各位说的初始化问题了。
      

  5.   

    class CustomerCareExecutive{
        String executiveName;
        int rating;
        public void displayDetails(){
            System.out.println(executiveName);
            System.out.println(rating);
        }
    }
    public class ExecutiveCollection {
        CustomerCareExecutive exObjects[] = new CustomerCareExecutive[3]; // Modified
        ExecutiveCollection(){
            for(int ctr=0;ctr!=3;ctr++){
                exObjects[ctr]=new CustomerCareExecutive();
            }
            exObjects[0].executiveName="Smart Cells Inc";
            exObjects[0].rating=Integer.parseInt("30");  // Modified
            exObjects[1].executiveName="AlkaTel";
            exObjects[1].rating=85;
            exObjects[2].executiveName="CellTalk Inc";
            exObjects[2].rating=60;
        }
        public void displayCollection(){
            for(int ctr=0;ctr!=3;ctr++){
                exObjects[ctr].displayDetails();
            }
        }
        public static void main(String arg[]){
            ExecutiveCollection collectionObj;
            collectionObj=new ExecutiveCollection();
            collectionObj.displayCollection();
            System.out.println("All Records displayed");
        }
    }