Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x in y is defined in an inaccessible class or interface, ID in structure

I am getting main.java: error: someId in someStruct is defined in an inaccessible class or interface but how can I solve this?

my main class:

import subdir.Subclass;  

public class main{  
  ...  
  Subclass.someArrayList.get(i).someString  
  ...  
}

my subdir.Subclass class:

package subdir;

public class Subclass{


  public static java.util.ArrayList<someStruct> someArrayList = new java.util.ArrayList<someStruct>(java.util.Arrays.asList(
    new someStruct(3, "string", "string"),
    new someStruct(4, "string", "string")
  ));

}



class someStruct
{
  public int someId;
  public String someString;
  public String someString2;
  public someStruct(int someId, String someString, String someString2) {
    this.someId = someId;
    this.someString = someString;
    this.someString2 = someString2;
  }
}
like image 825
Daniel Ruf Avatar asked Feb 03 '14 19:02

Daniel Ruf


2 Answers

If you want to access something from a different package, it must be public.

like image 162
SLaks Avatar answered Nov 08 '22 16:11

SLaks


You will not be able to access anything that is protected or private in another package. They must be public.

like image 31
Jordan.J.D Avatar answered Nov 08 '22 16:11

Jordan.J.D