Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: call() is not public in BTEST, cannot be accessed by outside package

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default call() is not public in BTEST, cannot be accessed by outside package

    Hello All,
    I have an issue. I created 2 java programs, a.java and b.java

    content of a.java:

    package test;
    import test1.*;
    publuc class ATEST {
    public static void main (String[] args) {
    BTEST.call();
    }
    }

    content of b.java:

    package test1;
    public class BTEST {
    string name;
    void call() {
    .
    .
    }
    }

    Getting call() is not public in BTEST; cannot be accessed by outside package.

    Question is b.java must be declared in this fashion. I need to add access modifiers so that call() and any constructors are the only things that are accessible from other packages. Any other method can only be accessed from the BTEST class.

    Your kind assistance would be greatly appreciated.

    Thanks,


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    call() is not public in BTEST; cannot be accessed by outside package.
    Why not make it public if you want to call it?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    how would i do this? Please help

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    You don't know how to make a method public?

    Controlling Access to Members of a Class

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    no. everything I try is not working.

    --- Update ---

    I'm a newbiw. I'm self teaching this language.

    --- Update ---

    if I make it public, I get non-static method call() cannot be referenced from a static context

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    Please post the code and the full text of the error messages.

    Continue reading the tutorial:
    http://docs.oracle.com/javase/tutori...classvars.html
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    Quote Originally Posted by ozman26 View Post
    no. everything I try is not working.

    --- Update ---

    I'm a newbiw. I'm self teaching this language.

    --- Update ---

    if I make it public, I get non-static method call() cannot be referenced from a static context
    Then you need to fix this error. Don't try to call the method without first creating an object of the class to call the method on.

  8. #8
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    content of a.java:

    package test;
    import test1.*;
    public class ATEST {
    public static void main (String[] args) {
    BTEST.call();
    }
    }

    content of b.java:

    package test1;
    public class BTEST {
    string name;
    public void call() {
    System.out.println ("Some text.....");
    }
    }


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method printAll() cannot be referenced from a static context
    at atest.ATEST.main(ATEST.java:30)
    Java Result: 1

    --- Update ---

    and how is this done based on my sample program. Please show me.

    --- Update ---

    Quote Originally Posted by curmudgeon View Post
    Then you need to fix this error. Don't try to call the method without first creating an object of the class to call the method on.
    and how is this done based on my sample program. Please show me.

    --- Update ---

    Quote Originally Posted by Norm View Post
    Please post the code and the full text of the error messages.

    Continue reading the tutorial:
    Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    content of a.java:

    package test;
    import test1.*;
    public class ATEST {
    public static void main (String[] args) {
    BTEST.call();
    }
    }

    content of b.java:

    package test1;
    public class BTEST {
    string name;
    public void call() {
    System.out.println ("Some text.....");
    }
    }


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method printAll() cannot be referenced from a static context
    at atest.ATEST.main(ATEST.java:30)
    Java Result: 1

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    content of a.java:

    package test;
    import test1.*;
    public class ATEST {
    public static void main (String[] args) {
    BTEST.call();
    }
    }

    content of b.java:

    package test1;
    public class BTEST {
    string name;
    public void call() {
    System.out.println ("Some text.....");
    }
    }


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method printAll() cannot be referenced from a static context
    at atest.ATEST.main(ATEST.java:30)
    Java Result: 1

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    non-static method printAll() cannot be referenced from a static context
    Please post the code that goes with the error message. There is no printAll() method in the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    Quote Originally Posted by Norm View Post
    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    Please post the code that goes with the error message. There is no printAll() method in the posted code.
    Sorry. Here you go.

    content of a.java:

    package test;
    import test1.*;
    public class ATEST {
    public static void main (String[] args) {
    BTEST.call();
    }
    }

    content of b.java:

    package test1;
    public class BTEST {
    string name;
    public void call() {
    System.out.println ("Some text.....");
    }
    }


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method call() cannot be referenced from a static context
    at atest.ATEST.main(ATEST.java:30)
    Java Result: 1

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    You keep ignoring this:
    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    You need t read this and ask questions if you don't understand it.
    http://docs.oracle.com/javase/tutori...classvars.html
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    I'm not ignoring anything. Here and I'll try again! Why would you need it in this fashion to begin with?

    Sorry. Here you go.

    content of a.java:

    package test;
     import test1.*;
     public class ATEST {
     public static void main (String[] args) {
     BTEST.call();
     } 
    }
     
    package test1;
     public class BTEST {
     string name;
     public void call() {
     System.out.println ("Some text.....");
     }
     }


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method call() cannot be referenced from a static context
    at atest.ATEST.main(ATEST.java:30)
    Java Result: 1

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    - non-static method call() cannot be referenced from a static context
    Did you read the tutorial? Do you have any questions about what you read?


    Why are you coding this statement: BTEST.call();
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    I'm calling it because I need to print some values.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: call() is not public in BTEST, cannot be accessed by outside package

    Sorry, I meant to ask: Why did you code the statement the way it is coded?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: November 8th, 2012, 07:55 AM
  2. Tutorial how to call OSGI service from EAR package
    By rcbandit2 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 4th, 2012, 10:15 AM
  3. Simple package problem, package does not exist error
    By Farmer in forum Object Oriented Programming
    Replies: 3
    Last Post: August 23rd, 2011, 11:18 AM
  4. Call by Reference & Call by Value
    By Lokesh in forum Java Theory & Questions
    Replies: 1
    Last Post: February 21st, 2011, 01:19 PM
  5. Replies: 10
    Last Post: September 6th, 2010, 04:48 PM