Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. compile error: string is private with powershell

compile error: string is private with powershell

Scheduled Pinned Locked Moved Java
javawindows-adminhelpquestionlearning
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shoysmTP
    wrote on last edited by
    #1

    a very beginner question... i'm a newbie in programming... just started java and read about packaging... i created i directory called firstproject and put a directory with one class inside of it and a FirstProject source file in the firstproject directory itself. i made a class in that package directory that has a private string in it and tried to invoke from FirstProject source file but getting compile error that the string is private... i tried changing the string into protected or even public but still getting this error... this is the class src file...

    package stickers;
    public class Sticker
    {
    private String note;

    Sticker(String note)
    {
    this.note = note;
    }

    public void displayNote()
    {
    System.out.println(note);
    }
    }

    this is the FirstProject src file...

    package firstproject;
    import stickers.Sticker;
    public class FirstProject
    {
    public static void main(String[] args)
    {
    Sticker sticker = new Sticker("hello sticky mehdi");
    sticker.displayNote();
    }
    }

    this is the actuall error: error: Sticker(String) is not public in Sticker; cannot be accessed from outside package

    L 1 Reply Last reply
    0
    • S shoysmTP

      a very beginner question... i'm a newbie in programming... just started java and read about packaging... i created i directory called firstproject and put a directory with one class inside of it and a FirstProject source file in the firstproject directory itself. i made a class in that package directory that has a private string in it and tried to invoke from FirstProject source file but getting compile error that the string is private... i tried changing the string into protected or even public but still getting this error... this is the class src file...

      package stickers;
      public class Sticker
      {
      private String note;

      Sticker(String note)
      {
      this.note = note;
      }

      public void displayNote()
      {
      System.out.println(note);
      }
      }

      this is the FirstProject src file...

      package firstproject;
      import stickers.Sticker;
      public class FirstProject
      {
      public static void main(String[] args)
      {
      Sticker sticker = new Sticker("hello sticky mehdi");
      sticker.displayNote();
      }
      }

      this is the actuall error: error: Sticker(String) is not public in Sticker; cannot be accessed from outside package

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to make your constructor public so other packages can access it:

      public class Sticker
      {
      private String note;

      public Sticker(String note)
      {
      this.note = note;
      }
      // ... etc

      I would recommend going to The Java Tutorials[^] and working through them.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups