导入包的方法时编译错误?

时间:2013-07-06 06:29:10

标签: java

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

我的包文件是:

 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()

提前感谢。

1 个答案:

答案 0 :(得分:3)

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

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

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