0

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.

1 Answer 1

3

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!

Sign up to request clarification or add additional context in comments.

3 Comments

i have tried that before only when i moved my methods outoff main() it is giveing error that package doesnot exists
@user2083041 can u move your method outside the main method and share the updated code
i have uploaded my SimpleCustomerService code i am getting the same error package cannot find

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.