我在目录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
如何解决这个问题?
Upd:我尝试使用命令重建项目:
javac LibUtil/Item.java
javac Library.java
答案 0 :(得分:0)
在我的源文件中,我找到了Item.java的副本。并且在这个重复的类中,Item没有public修饰符。感谢所有本主题答案的作者