[英]Error with package import in java
I have package LibUtil with file Item.java in directory LibUtil. 我在目录LibUtil中有文件Item.java包LibUtil。 In this file i have public class Item
在此文件中,我有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;
}
}
I import this class from LibUtil. 我从LibUtil导入此类。
import LibUtil.Item;
public class Library{
public static void main(String[] args){
Item test = new Item(1,"XYZ","Alpha");
}
}
When i'm traing compile this project compiler produces output like this: 当我训练编译时,此项目编译器将产生如下输出:
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
How solve this problem? 如何解决这个问题?
Upd: i try to rebuild project with command: 更新:我尝试使用命令重建项目:
javac LibUtil/Item.java
javac Library.java
In my source files i find duplicate of Item.java. 在我的源文件中,我找到了Item.java的重复项。 And in this duplicate class Item hasn't public modifier. 并且在此重复的类中,Item没有公共修饰符。 Thank's for all author of answers in this topic 感谢所有有关此主题的作者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.