0

SimpleCustomer パッケージを作成し、SimpleCustomerService ファイルで使用しました。前進

私のパッケージファイルは次のとおりです。

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

最初のエラーは public で、2 番目のエラーは getALLlCustomers() で発生します。

前もって感謝します。

4

1 に答える 1

3

メインメソッドにメソッドを埋め込もうとしているようですが、これがエラーの原因であると信じています:

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

なぜそれをしたいのかわからないが、それは許されていません。getAllCustomers メソッドをメイン メソッドから移動して、それが役立つかどうかを確認する必要があります。

于 2013-07-06T06:32:57.753 に答える