Classes cannot be accessed from outside package

前端 未结 7 1944
既然无缘
既然无缘 2020-12-11 14:43

I have two packages. The class I want to import from the first package is declared as PUBLIC. Despite, when I test a file from the second package it shows me compilation err

相关标签:
7条回答
  • 2020-12-11 14:55

    Maybe you should try removing "new" keyword and see if works. Because last time I got this error when I tried creating Typeface something like this:

    Typeface typeface = new Typeface().create("Arial",Typeface.BOLD);
    
    0 讨论(0)
  • 2020-12-11 14:56

    closeDrawers(boolean) is not public in android.support.v4.widget.DrawerLayout. Cannot be accessed from outside package

    @Override
    public void onBackPressed() {
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
           super.onBackPressed();
        }
    }
    
    0 讨论(0)
  • 2020-12-11 14:58

    Do you by any chance have two PUBLICclass classes in your project, where one is public (the one of which you posted the signature here), and another one which is package visible, and you import the wrong one in your code ?

    0 讨论(0)
  • 2020-12-11 15:06

    Check the default superclass's constructor. It need be public or protected.

    0 讨论(0)
  • 2020-12-11 15:09

    Note that the default when you make a class is not public as far as packages are considered. Make sure that you actually write public class [MyClass] { when defining your class. I've made this mistake more times than I care to admit.

    0 讨论(0)
  • 2020-12-11 15:18

    Let me guess

    Your initial declaration of class PUBLICClass was not public, then you made it `Public', can you try to clean and rebuild your project ?

    0 讨论(0)
提交回复
热议问题