Java 导入包的方法时发生编译错误?
我已经创建了一个包SimpleCustomer,并在SimpleCustomerService文件中使用了它。我已经为SimpleCustomer生成了.class文件,其中当我编译SimpleCustomerService文件时出现了错误。我无法解决我的错误。我是java新手。提前感谢 我的包文件是:Java 导入包的方法时发生编译错误?,java,Java,我已经创建了一个包SimpleCustomer,并在SimpleCustomerService文件中使用了它。我已经为SimpleCustomer生成了.class文件,其中当我编译SimpleCustomerService文件时出现了错误。我无法解决我的错误。我是java新手。提前感谢 我的包文件是: package com.adobe.objects; import java.util.Date; public class SimpleCustomer { private int cu
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;
}
}
package.com.adobe.services;
导入com.adobe.objects.SimpleCustomer;
导入java.util.ArrayList;
导入java.util.Date;
公共类SimpleCustomerService
{
公共静态void main(字符串参数[])
{
}
ArrayList getAllCustomers()
{
ArrayList客户=null;
尝试
{
int numberOfCustomers=20;
SimpleCustomer=null;
客户=新的ArrayList();
对于(int loopCounter=1;loopCounter您似乎试图在主方法中嵌入一个方法,我认为这是导致错误的原因:
public static void main(String args[])
{
ArrayList<SimpleCustomer> getAllCustomers()
{
publicstaticvoidmain(字符串参数[])
{
ArrayList getAllCustomers()
{
不确定为什么要这样做,但这是不允许的。您应该将getAllCustomers方法移出main方法,看看是否有帮助!您似乎试图在main方法中嵌入一个方法,我相信这是导致错误的原因:
public static void main(String args[])
{
ArrayList<SimpleCustomer> getAllCustomers()
{
publicstaticvoidmain(字符串参数[])
{
ArrayList getAllCustomers()
{
不确定为什么要这样做,但这是不允许的。您应该将getAllCustomers方法移出main方法,看看是否有帮助!我以前尝试过,只是在我将方法移出main()时这是一个给定的错误,该包不存在exists@user2083041你能把你的方法移到main方法之外并分享更新的代码吗我上传了我的SimpleCustomerService代码我收到了相同的错误包找不到我以前只有在我把我的方法移出main()时才尝试过这是一个给定的错误,该包不存在exists@user2083041你能把你的方法移到主方法之外并分享更新的代码吗?我已经上传了我的SimpleCustomerService代码,我收到了相同的错误包,找不到