Question about access non-public class from other package.

Hi, everyone!
Suppose class A and class B are in the same java file of package pkg1
-- A.java. So, A is a public class and B is a non-public class.
If I want to access class B from another class class C and class
C is in package pkg2. When compiling, an error occurs indicating
that class B is not visible to class C.
So, If I defined serveral classes in one java file and I want to
access every class from other package. How should I do?
(I think in one java file, there should be only one public class and
only the public class can be accessed from other package.)
Thanks in advance,
George

So, If I defined serveral classes in one java file and
I want to
access every class from other package. How should I
do? As you already seem to know, there is at most one public class allowed per source file (at least, with javac and most popular compilers). So if you want more than one public class, you will need to use more than one file...

Similar Messages

  • Can't access non ejb classes from JSP - NoClassDefFound error

              Hi,
              I have one session ejb which has a method returning a collection of non ejb class objects (say of Class 'Foo').
              The method signature is like :
              "Collection getFinacialData() throws RemoteException"
              It is working fine with normal java clients. Now when I run this from a JSP it gives a "NoClassDefFoundError". I kept class 'Foo' and the remote interface of the session bean in the same package and also in the same ejb jar file. Also I am running JSP and ejb in same WL server(ver 5.1, SP8 on solaris). What I have done is only deployed the bean jar file. Do I need to do anything more?
              thanks in advance.
              

    I ran into a similar problem. I solved it by putting the client classes for
              accessing my EJB in the WebLogic POST_CLASSPATH in the startWebLogic script
              file:
              set POST_CLASSPATH=d:\weblogic\myserver\myClient.jar
              For more information on class visibility between the JSP and EJB class
              loaders, check out
              http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_deployover.html#1056256
              Rick
              "niroja" <[email protected]> wrote in message
              news:3a6ed903$[email protected]..
              >
              > Hi,
              >
              > I have one session ejb which has a method returning a collection of non
              ejb class objects (say of Class 'Foo').
              > The method signature is like :
              > "Collection getFinacialData() throws RemoteException"
              > It is working fine with normal java clients. Now when I run this from a
              JSP it gives a "NoClassDefFoundError". I kept class 'Foo' and the remote
              interface of the session bean in the same package and also in the same ejb
              jar file. Also I am running JSP and ejb in same WL server(ver 5.1, SP8 on
              solaris). What I have done is only deployed the bean jar file. Do I need to
              do anything more?
              >
              > thanks in advance.
              >
              

  • Loading fails, when classes from other packages are referenced

    My applet follows a simple package structure.
    There's package P1 and there's another package in it P2 (P1.P2)
    P1 contains Applet class A.
    P2 contains another class C and interface I. C implements I.
    A contains a reference of C, which is initialized in the constructor. The use in the constructor of the A (the applet) is something like this
    public A () {
              reg = ToolkitRegistry.getEntry (); //where reg is a reference of type ToolkitRegistry.
              // some more code
              i = (I) C.getC (); //where i is a reference of type I.
    }Trying to load this applet throws error saying "Package Loading failed". Important is to note that the loading occurs successfully by commenting out this line           i = (I) C.getC (); //where i is a reference of type I. , without any other change.
    I understood this to be some problem with the AIDs assigned to both the packages while converting. Unsure of what's the correct way to assign the PIX values, I've been trying some permutation/combinations, it doesn't seem to work.
    Has neone already faced this problem & knows the solution? (The specs aren't much help)

    One more point ..... I mentioned commenting the statements, I DO NOT commment the other statements referencing the other package. This means that the loading IS succesfull, even when these two lines reside in there.
    1. import P1.P2.*; 2. private I i = null;Above two lines pass the loader. The object creation gets stuck.
    Wonder if the package references are actually alright, because JVM wud've treated both situations in a similar way. JCVM is ofcourse different but JCVM spec does not say nething abt this situation (rem: everything is public, so the access control restrictions also do not apply)
    are there ne instantiation restrictions? [In my case, it's in the constructor thread)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Weird Can not access class from outside package problem

    Hi, I have this problem and it seems the error message is very clear what the problem is but I did make the GeneralTestResult class PUBLIC already. What could be wrong? I did search for it but this is too general and didn't find any solution. Anyone can point out the problem? TIA.
    public abstract class GeneralTestResult
      public static int FAILING_THRESHOLE = 25;
      public abstract String getTestName();
      public abstract boolean isPassed();
      public abstract int getLeftEyeResult();
      public abstract int getRightEyeResult();
      public abstract Calendar getTestDate();
    // in a different file
    package VisionSaver.Tests.TestResults;
    import java.util.*;
    public class AcuityORContrastTestResult extends GeneralTestResult
      private String m_testName;
      private int m_leftEyeVision, m_rightEyeVision;
      private Calendar m_testDate;
    // in a different file
    package VisionSaver.Tests;
    import VisionSaver.Tests.TestResults.*;
    public class Acuity extends VirtualKeyboard implements ActionListener, Runnable, WindowListener
    AcuityORContrastTestResult r = new AcuityORContrastTestResult(...);
    }The compiling error is:
    "Acuity.java": GeneralTestResult() in VisionSaver.Tests.TestResults.GeneralTestResult is not defined in a public class or interface; cannot be accessed from outside package at line 529, column 40

    The GeneralTestResult class is a packaged class. Sorry, when I cut and paste, I didn't copy everything. So here is the complete GeneralTestResult file:
    package VisionSaver.Tests.TestResults;
    import java.util.*;
    public abstract class GeneralTestResult
      public static int FAILING_THRESHOLE = 25;
      public abstract String getTestName();
      public abstract boolean isPassed();
      public abstract int getLeftEyeResult();
      public abstract int getRightEyeResult();
      public abstract Calendar getTestDate();
    }From the compiler's message, it seems like the import is OK. It just won't allow me to access non-public class but my classes here are declared public. Any other ideas? TIA

  • Public main method in a non-public class

    Hi,
    It is said that main method in a java class must be public so that it can be invoked by JVM. This works even if the class itself has default modifier.
    But while programming, any method (be it public) of a class with default access modifier from one package can't be accessed by classes from other packages. For example,
    1. Consider class A in package a.
    package a;
    class A {
    public void methA() {}
    2. Now consider class B in pakage b.
    package b;
    class B {
    void methB() {
    // Here it can't access class A and its method methA()
    So how does JVM invoke the main method of a class with default access modifier. Assume that the class is in some package a.b.c
    Regards,
    Amit

    Hi,
    Maybe this can also be beneficial for you.
    Standalone applications don't necessarily have init and start methods. They must have a public static void main routine to start things off. The main routine typically creates some object of the master class. It can't use any non-static variables or methods in the class with the implied this, since there is no this object. It typically quickly returns. Then the event loop processing starts. Even the static main method must live inside some public class, or at least in the top class, the first class and the class for whom the source file is named. There are no such thing as standalone static methods in Java. The signature of the main class must look exactly like this. Cut and paste it to be sure:

  • Question: about accessing Nik collection through Lightroom

    I have recently purchased and installed Nik collection. I have no problem reaching the plug-ins in Photoshopbut can't in Lightroom (except for HDR)

    Thanks!  Technology senses my fear and always makes it difficult for me! Ha! I can use the Nik programs so if I have to, I'll work on them there.
    Date: Sat, 13 Apr 2013 16:27:45 -0700
    From: [email protected]
    To: [email protected]
    Subject: question: about accessing Nik collection through Lightroom
        Re: question: about accessing Nik collection through Lightroom
        created by trihelm2 in Photoshop Lightroom - View the full discussion
    I suspect there are potential issues on some systems with the Google "combined" version, when I installed it I had recieved a copy of the Google complete version free because of my purchase history. I was advised that I could install over the Individual Plugins I had. I never got as far as trying it with Lightroom, only in Elements. The plugins appeared but the load times were abysmal and I mean realy bad , far longer than the Nik individual Installs, so I dumped it and reverted to the originals. Pity cos I wanted the Sharpen Plugin that I have'nt got. After reverting all was back to normal The Nik individual Plugins load very quickly. It was this that convinced me there is a difference in the Google setup.There are people on here with far more knowledge than me, hopefully one of them can help you, alternatively you might try asking Google for help with this.
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5232723#5232723
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5232723#5232723
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5232723#5232723. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Lightroom by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Calling a object of class from other class's function with in a package

    Hello Sir,
    I have a package.package have two classes.I want to use object of one class in function of another class of this same package.
    Like that:
    one.java
    package co;
    public class one
    private String aa="Vijay";  //something like
    }main.java:
    package co;
    import java.util.Stack;
    public class main extends Stack
    public void show(one obj)
    push(obj);
    public static void main(String args[])
    main oo=new main();
    }when I compile main class, Its not compile.
    Its give error.can not resolve symbol:
    symbol: class one
    location: class co.main
    public void show(one obj)
                              ^Please help How that compile "Calling a object of class from other class's function with in a package" beacuse I want to use this funda in an application

    kumar.vijaydahiya wrote:
    .It is set in environment variable.path=C:\bea\jdk141_02\bin;.,C:\oraclexe\app\oracle\product\10.2.0\server\bin;. command is:
    c:\Core\co\javac one.javaIts compiled already.
    c:\Core\co\javac main.javaBut it give error.
    Both java classes in co package.Okay, open a command prompt and execute these two commands:
    // to compile both classes:
    javac -cp c:\Core c:\Core\co\*.java
    // to run your main-class:
    java -cp c:\Core co.main

  • Accessing a Java class from C when class is in a package

    I'm accessign a java class from C using JNI: The JVM exists and I can access the class fine:
    jclass cls; //java class
    cls = (*env)->FindClass(env, "MyClass");
    However when I put the class in a package I can't access it
    cls = (*env)->FindClass(env, "mypackage.MyClass");
    Does anyone know How I can access a java class in a package using JNI.
    Thanks
    ..

    Been a while since I've done anything with JNI, But... Did you try this:
    cls = (*env)->FindClass(env, "mypackage/MyClass");

  • How to access a Java class from view controller?

    Hi All,
    I have created a Test.java class file from Navigator view under
    Src --> Packages --> com.sap.MyProject.
    When I try to access the Test class from view controller,
    I getting this error "Test cannot be resolved or is not a type".
    How do I fix this?
    Thanks
    Sundar

    Hi,
    I have created a Test.java class file from Navigator view under
    Src --> Packages --> com.sap.MyProject.
    After this you can goto the context of your View and define the VA goto the type of VA and click on the right side button and go to java native type and type your java file name click you name .
    that means the jave file s assigned to VA.
    U can utilize thrut that VA.
    Thanks,
    Lohi.

  • Need quick TIP: remove "Copy access and configuration settings" from added package

    I added a modified package in APPVMAN with the option "Copy access and configuration settings".
    Package is unpublished. But shows AD groups as a current package because I used the option "Copy access and configuration settings"
    QUESTION:
    How to Remove (and then add) the option "Copy access and configuration settings" from added package.
    Cannot find it.
    Thanks.
    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    sorry for the panic :)
    before publishing an updated package to existing groups of initial package I hit the option
    "Copy access and configuration settings".
    But first I wanted to test it for TEST group. Didn't think that AD settings will be applied (do it first time).
    Just to confirm:
    1. I will remove current groups from updated(unpublished package)
    2. Will add Test group and test the package.
    3  In case it is OK I can then add removed(needed) groups.
    I want to be sure that after removing and adding needed groups all other settings will be intact.
    Thanks.
    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

  • How to import a class from a package at the same level

    Hello friends,
    i have a class as Plaf.java
    as
    package org.vaibhav.swing.plaf;
    import java.awt.*;
    import javax.swing.*;
    public class Plaf {
    other code
    }as you see, this is in org.vaibhav.swing.plaf package.
    I have one more class as
    package org.vaibhav.swing.frames;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StartFrame extends JFrame implements ActionListener {
    other code
    }and this class is in package org.vaibhav.swing.frames
    Please hlp me how to use the class Plaf in StartFrame.java. Rather what import statement should i use in StartFrame.java.
    please help.
    thank you
    Message was edited by:
    vaibhavpingle

    but it then gives me this error
    StartFrame.java:11: package org.vaibhav.swing.plaf
    does not exist
    import org.vaibhav.swing.plaf.*;
    Have you first compiled Plaf.java and saved it in this directory strucuture
    /org/vaibhav/swing/plaf/
    And also have you set your classpath to the parent directory of org folder.
    Message was edited by:
    qUesT_foR_knOwLeDge

  • How do I move objects from other package to a newly created one?

    How do I move objects from other package to a newly created one?
    Thanks!

    Dear Anthony Pham ,
    for changing objects from one package to another package
    open that object for example Report
    open the report and than click GOTO select OBJECT DIRECTIORY ENTRY
    than it will open a popup in that popup click the change and give the new package
    Thanks
    Surendra

  • Accessing a public array from extra class.

    I am trying to access a public array that I declared in my main class from a separate class. I am a bit confused about why this is not working.
    The method search in the extra class is called in the extra class in part one of the nextKeystream method. How can I get it to use the int array "key". That I declared in the MainSolitaireDriver?
    Thanks
    My main class:
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class MainSolitaireDriver
       int pcount = 0;
       public int[] key = new int[26];    
       public MainSolitaireDriver()
           getValues();
            public void getValues()
                try
                    Scanner inFile = new  Scanner(new File("input.txt"));
                    for (int counter = 0; counter < key.length; counter++ )
                        key[counter]= inFile.nextInt();
                        System.out.print(key[counter]+" ");
                catch(FileNotFoundException e )
                e.printStackTrace();
                System.err.print("Failure- File Not Found");
         public static void main (String[] args)
                /*String whereInTheWorldMyFileShouldBe = new File("input.txt").getAbsolutePath();
    System.out.println(whereInTheWorldMyFileShouldBe); */
    }My extra class:
    public class Solitaire
         private Deck deck;
         *  Initialize the deck from the current key deck ordering.
         public Solitaire (int[] shuffle)
              deck = new Deck(shuffle);
            public void getArray(int[] Array)
            public int search(int [] span, int target)
                for (int indexcount = 0; indexcount < span.length; indexcount++)
                    if (span[indexcount]==target)
                        return indexcount;
            public void getArray(int[] a)
         *  Returns the next keystream generated by the Solitaire  Algorithm
         public int nextKeystream()
              // Step one: Move Joker A one card down.
                    int jokerAindex = search(MainSolitaireDriver(key), 27);
                    System.out.print(jokerAindex);
              // Step two: Move Joker B two cards down.
              // Step three: Perform a triple cut.
              // Step four: Perform a count cut.
              // Step five: Find the output card.
              return 0;
         *  Returns the ciphertext corresponding to the specified
       *  plaintext, according to the current key deck ordering.
         public String encrypt(String plaintext)
              return "";
         *  Returns the plaintext corresponding to the specified
       *  ciphertext, according to the current key deck ordering.
         public String decrypt(String ciphertext)
              return "";
    }

    Main Class
    import java.util.*;
    import java.io.*;
    import java.util.Scanner;
    public class MainSolitaireDriver
       int pcount = 0;
       public int[] key = new int[26];    
       public MainSolitaireDriver()
           getValues();
            public void getValues()
                try
                    Scanner inFile = new  Scanner(new File("input.txt"));
                    for (int counter = 0; counter < key.length; counter++ )
                        key[counter]= inFile.nextInt();
                        System.out.print(key[counter]+" ");
                catch(FileNotFoundException e )
                e.printStackTrace();
                System.err.print("Failure- File Not Found");
         public static void main (String[] args)
                /*String whereInTheWorldMyFileShouldBe = new File("input.txt").getAbsolutePath();
    System.out.println(whereInTheWorldMyFileShouldBe); */
    }Solitaire Class (not main)
    public class Solitaire
         private Deck deck;
         *  Initialize the deck from the current key deck ordering.
         public Solitaire (int[] shuffle)
              deck = new Deck(shuffle);
            public void getArray(int[] Array)
            public int search(int [] span, int target)
                for (int indexcount = 0; indexcount < span.length; indexcount++)
                    if (span[indexcount]==target)
                        return indexcount;
            public void getArray(int[] a)
         *  Returns the next keystream generated by the Solitaire  Algorithm
         public int nextKeystream()
              // Step one: Move Joker A one card down.
                    int jokerAindex = search(MainSolitaireDriver.key, 27);
                    System.out.print(jokerAindex);
              // Step two: Move Joker B two cards down.
              // Step three: Perform a triple cut.
              // Step four: Perform a count cut.
              // Step five: Find the output card.
              return 0;
         *  Returns the ciphertext corresponding to the specified
       *  plaintext, according to the current key deck ordering.
         public String encrypt(String plaintext)
              return "";
         *  Returns the plaintext corresponding to the specified
       *  ciphertext, according to the current key deck ordering.
         public String decrypt(String ciphertext)
              return "";
    }

  • Easy question: Give access to a class in another class.

    Stupid title, but dont know how to express myself :P Sorry for that.
    To the problem. Never had this problem before, and I know its a really easy solution to this.
    I have my Main class, which creates a MyView class. Inside this class, I make to new classes(or instances of classes i've already made), MyPanel and MyToolsPanel. Now I want to add buttons inside the MyToolsPanel class, and add actionlisteners to these buttons inside MyPanel.
    What I'v always done to grant access to MyToolsPanel inside of MyTools, is to simply add a
    //this is the MyPanel class
    MyToolsPanel mtp;
    public void setMtp(MyToolsPanel mtp){
    this.mtp = mtp;
    }and then in the MyView class which create these to classes, I put a command: mp.setMtp(mtp);
    When I run this it doesnt work.. Why? Should be easy to solve, since it obviously is a stupid problem that I just dont see. :P Feeling kind of stupid to ask this question, but this is how it is...
    EDIT: I might have to implement actionListener inside the MyToolsPanel class?
    Edited by: Stianbl on Sep 28, 2008 4:59 PM

    one way:
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    * Subclasses JPanel, can send text out via the getText() method
    * can hook into button press via addActionListener
    * @author Pete
    public class PanelCommSender extends JPanel
      private JTextField sendingField = new JTextField(12);
      private JButton sendButton = new JButton("Send");
      public PanelCommSender()
        add(sendingField);
        add(sendButton);
      public void addActionListener(ActionListener al)
        // attach this listener to the button
        sendButton.addActionListener(al);
       * call this to get the text currently in the textfield
       * @return String text
      public String getText()
        return sendingField.getText();
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    * Subclasses JPanel, receives text from another class
    * @author Pete
    public class PanelCommReceiver extends JPanel
      private JTextField showResultsField = new JTextField(12);
      public PanelCommReceiver()
        showResultsField.setEditable(false);
        add(new JLabel("Results from other panel: "));
        add(showResultsField);
       * call this to set text of textField
       * @param text
      public void setText(String text)
        showResultsField.setText(text);
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    public class PanelCommControl
      private static void createAndShowUI()
        // create new instances of the receiving and sending panels:
        final PanelCommReceiver receivePanel = new PanelCommReceiver();
        final PanelCommSender sendPanel = new PanelCommSender();
        // let the communicate w/ each other
        sendPanel.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            receivePanel.setText(sendPanel.getText());
        // place the receiving JPanel into a JFrame
        JFrame frame = new JFrame("Receiving Panel");
        frame.getContentPane().add(receivePanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(300, 300)); // make it bigger so it can be seen
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        // place the sending JPanel into a JDialog
        JDialog dialog = new JDialog(frame, "Sending Panel", false);
        dialog.getContentPane().add(sendPanel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            // run the whole show in a thread-safe manner
            createAndShowUI();
    }

  • Are there non-public classes in Java SDK?

    Or are ALL classes in all packages of the Java SDK public?
    I have looked in the sources spot checking and didn't find a non public (default) class.
    If all classes are public, why?
    There exists a means in Java language to define a class as default ("class MyClass" instead of "public class MyClass") visibility. So why isn't it used by Java SDK (if this is really true)?

    I dont know what language you're programming in.
    If you don't specify
    public class
    or
    private class
    the class is "protected".
    Read the spec.If you read the spec, you'll see that, with respect to a class:
    (per section 6.6.2) Classes from outside the package the class lives in that extend the class have access to protected members.
    (per section 6.6.5) Classes from outside the package this thing lives in that extend this class do not have access to default members.
    Relevant part of section 6.6.5 (Example: Default-Access Fields, Methods, and Constructors) is:
    If none of the access modifiers public, protected, or private are specified, a class member or constructor is accessible throughout the package that contains the declaration of the class in which the class member is declared, but the class member or constructor is not accessible in any other package.
    This is default access, not protected access
    Lee

Maybe you are looking for

  • My iPhoto spins but doesn't open

    iPhoto spins but does not open

  • Severe Screen Artefacts post Mountain Lion Upgrade

    I recently upgraded to Mountain Lion direct from Snow Leopard.  Ever since I have been getting weird vertical lines drwn on my iMac screen. They don't appear all the time.  They appear in windows when I move the window around the screen. They sometim

  • Numbers has just stopped working.

    Numbers has stopped working. It will not load and I can't open any numbers files. How do I solve this problem?

  • Can Quicktime Pro capture Micromv?

    hey guys, i have been researching this alot, and have had alot of trouble about this, i have a sony dcr-ip5 camera that records micromx format, yea remember those things??? anyways i read somewhere that quicktime pro is able to import that video form

  • Lightroom's large memory footprint

    After massaging many pictures in "develop" mode, the system began to become very slow (like locking up for 30 seconds). I opened process explorer and found LightRoom was consuming 1.8Gig of virtual memory and had a working set of about 1.2Gig. This s