user2083041
user2083041

Reputation: 513

Compilation Error while importing methods of package?

i have created a package SimpleCustomer and used it in SimpleCustomerService file.I have generated .class file for SimpleCustomer where as when i am compiling SimpleCustomerService file it is given errors .i couldn't resolve my error.i am new to java.thanks in advance

my package file is:

 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;
}
}

and my file which uses this package is:

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;
}
}

my error is: illegal start of expression :public ArrayList getAllCustomers() error 2: error ;excepted :public ArrayList getAllCustomers()

the first error is at public and second error is at getALlCustomers()

thanks in advance.

Upvotes: 0

Views: 114

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

It seems you are trying to embed a method in your main method, which is i belive causing the error:

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

Not sure why you want to do it, but it is not permissible. You should move your getAllCustomers mehthod out of main method and see if it helps!

Upvotes: 3

Related Questions