0

我创建了一个包 SimpleCustomer 并在 SimpleCustomerService 文件中使用它。我为 SimpleCustomer 生成了 .class 文件,当我编译 SimpleCustomerService 文件时,它给出了错误。我无法解决我的错误。我是 java.thanks 的新手进步

我的包文件是:

 package com.adobe.objects;
 import java.util.Date;
public class SimpleCustomer
{
 private int customerId;
 private String customerName;
 private String customerAddress;
 private String customerType;
 private Date entryModifiedDate;

 public int getCustomerId()
 {
   return this.customerId;
 }
 public void setCustomerId(int customerId) {
  this.customerId = customerId;
}
public String getCustomerName() {
return this.customerName;
}
public void setCustomerName(String customerName) {
 this.customerName = customerName;
}
public String getCustomerAddress() {
return this.customerAddress;
 }
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
public String getCustomerType() {
return this.customerType;
}
public void setCustomerType(String customerType) {
  this.customerType = customerType;
}
public void setEntryModifiedDate(Date entryModifiedDate) {
 this.entryModifiedDate = entryModifiedDate;
}
public Date getEntryModifiedDate() {
  return this.entryModifiedDate;
}
}

我使用这个包的文件是:

package com.adobe.services;

  import com.adobe.objects.SimpleCustomer;
  import java.util.ArrayList;
  import java.util.Date;

  public class SimpleCustomerService
   {
  public static void main(String args[])
     {

  }

  ArrayList<SimpleCustomer> getAllCustomers()
   {
     ArrayList customers = null;
  try
   {
  int numberOfCustomers = 20;
  SimpleCustomer customer = null;
  customers = new ArrayList();
  for (int loopCounter = 1; loopCounter <= numberOfCustomers; loopCounter++)
  {
    customer = new SimpleCustomer();
    customer.setCustomerId(loopCounter);
    customer.setCustomerName("Customer " + loopCounter);
    customer.setCustomerType("Organization " + loopCounter);
    customer.setCustomerAddress("Road # " + loopCounter + ", Bangalore, India");
    customer.setEntryModifiedDate(new Date());
    customers.add(customer);
  }
}
catch (Exception e)
{
  throw new RuntimeException(e);
}
return customers;
}
}

我的错误是:表达式的非法开始:public ArrayList getAllCustomers() 错误 2:错误;例外:public ArrayList getAllCustomers()

第一个错误是公开的,第二个错误是 getALLCustomers()

提前致谢。

4

1 回答 1

3

您似乎正在尝试在您的主要方法中嵌入一个方法,我相信这会导致错误:

public static void main(String args[])
{
   ArrayList<SimpleCustomer> getAllCustomers()
   {

不知道为什么要这样做,但这是不允许的。您应该将 getAllCustomers 方法移出 main 方法,看看它是否有帮助!

于 2013-07-06T06:32:57.753 回答