我在 LibUtil 目录中使用文件 Item.java 打包 LibUtil。在这个文件中我有public class Item
package LibUtil;
public class Item
{
static protected int id=0;
protected int type;
protected String name;
protected String category;
public Item(int type,String name,String category)
{
id++;
this.type = type;
this.name = name;
this.category = category;
}
public int GetId()
{
return id;
}
public int GetType(){
return type;
}
public void SetType(int type){
this.type = type;
}
public String GetName(){
return name;
}
public void SetName(String name){
this.name = name;
}
public void SetCategory(){
this.category = category;
}
public String getCategory(){
return category;
}
}
我从 LibUtil 导入这个类。
import LibUtil.Item;
public class Library{
public static void main(String[] args){
Item test = new Item(1,"XYZ","Alpha");
}
}
当我训练编译这个项目编译器产生这样的输出:
Library.java:1: LibUtil.Item is not public in LibUtil; cannot be accessed from outside package
import LibUtil.Item;
^
Library.java:4: cannot find symbol
symbol : class Item
location: class Library
Item test = new Item(1,"XYZ","Alpha");
^
Library.java:4: cannot find symbol
symbol : class Item
location: class Library
Item test = new Item(1,"XYZ","Alpha");
^
3 errors
如何解决这个问题?
更新:我尝试使用命令重建项目:
javac LibUtil/Item.java
javac Library.java