简体   繁体   中英

Error with package import in java

I have package LibUtil with file Item.java in directory LibUtil. In this file i have 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.

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. And in this duplicate class Item hasn't public modifier. Thank's for all author of answers in this topic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM