Import a Class of Package in the Same Subdirectory of the Classpath

Hi. I compiled the following "Package" program code without problem:
package ch09Fig6;
public class Point {
protected int x, y; // coordinates of the Point
// no-argument constructor
public Point() { setPoint( 0, 0 ); }
// constructor
public Point( int a, int b ) { setPoint( a, b ); }
// Set x and y coordinates of Point
public void setPoint( int a, int b )
x = a;
y = b;
// get x coordinate
public int getX() { return x; }
// get y coordinate
public int getY() { return y; }
// convert the point into a String representation
public String toString()
{ return "[" + x + ", " + y + "]"; }
When I compiled the following second program code:
import javax.swing.JOptionPane;
import Point;
public class Test {
public static void main( String args[] )
Point p = new Point( 72, 115 );
String output;
output = "X coordinate is " + p.getX() +
"\nY coordinate is " + p.getY();
p.setPoint( 10, 10 );
// use implicit call to p.toString()
output += "\n\nThe new location of p is " + p;
JOptionPane.showMessageDialog( null, output,
"Demonstrating Class Point",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
I got an error:
C:\jdk1.3.1\jhtp3\mypack>javac Test.java
Test.java:4: cannot access Point
bad class file: C:\jdk1.3.1\jhtp3\mypack\Point.class
class contains wrong class: ch09Fig6.Point
Please remove or make sure it appears in the correct subdirectory of the classpath.
import Point:
1 error.
I know "import Point:" is wrong, but I do not know how to correct it - import 'Point' that is a class of my Package into the "Test". Point.java and Test.java are in the same folder. Please tell me how to correct "import Point:" and make these two programs work together.
Thanks in adavance,
BigOcean

Thanks, jdaguet and gdasson.
(1) jdaguet: import ch09Fig6.Point; or import ch09Fig6.*; does not work - it generated 2 errors that are more serious than one I had.
(2) gdasson: I copied the 2 programs from a book (I just changed the import "Point"; for my PC) and tried to learned that way. So I do not want combine the 2 programs.
Any more help is appreciated.
BigOcean

Similar Messages

  • Importing existing classes loses package identity in 9.0.2

    I have tried several ways, but everytime I import existing classes, they all go to Miscellaneous Files and won't display under their packages. This is from disk or from source code control (CVS). This works fine with the same exact classes and directories under JDeveloper 3.1.1. It seems simple, but it is frustrating. Any suggestions?

    Hi,
    This is normally because the Source Path setting (under Common->Input Paths in project settings) is not set to the correct directory. You should get a prompt asking if you want to add the correct path to the source path when adding files to a project.
    Thanks,
    Brian

  • How can I import my class or package in JSP?

    Hello.
    I develop jsp. When I assign variables in jsp, everything work fine. For Example:
    connStr="jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    But I want put some variables inside class or package, so using text editor I created and compiled package:
    package Pack1;
    public class Test1 extends java.lang.Object {
    public static void main(String[] args) {
    String ConnStr = "jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    or class
    class Test1 {
    public static void main(String[] args) {
    String connStr = "jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    But as soon as I put in my jsp line
    <%@ page import="Test1" %> or <%@ page import="Pack1.*" %>
    I always have an error.
    JSP Error:
    Request URI:/DateN/search/Search.jsp
    Exception:
    oracle.jsp.provider.JspCompileException:
    Errors compiling:e:\orant\oem8i\apache\apache\htdocs\daten\_pages\_daten\_search\_Search.java
    C:\orant\oem8i\apache\apache\htdocs\daten\_pages\_daten\_search\_Search.java:12: Package DateN not found in import.
    import Pack1.*; (or Test1)
    ^
    1 error
    I using OEM2.2 with Apache-Server under Win2000. I put my classes:
    Test1 in package: in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes\Pack1
    If just class, when just in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes
    If I using just class, when I put just in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes.
    Im stack. Anybody can help?
    Thank you.

    Another way. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Secrets of the iPad Camera Connection Kit
    http://howto.cnet.com/8301-11310_39-57401068-285/secrets-of-the-ipad-camera-conn ection-kit/
     Cheers, Tom

  • How to import a class that is in the database?

    Here's the picture: I have a server running on a machine and the client side is a stored procedure located in the database. Instead of writing multiple parameters on the stream, I send a Map of parameters. Therefore, both sides of the server needs to "know" the keys of my parameters in the Map. So I end up declaring constants in both the client and server class.
    Is there a way for the server to import the static content of the client class that's in the database? ( Or vice-versa )
    Thanks in advance!

    Is this a JDBC question?
    Meta data solutions mean that you will only find problems at runtime that would be obvious at compile time with a non-metadata solution. Code generation makes production of large numbers of these easy.
    But if you want metadata then you create a seperate class in a seperate package which holds the constants. The specifics depend on the implementation but you will typically have one class for each 'type' that is supported.
    That package is used by both the server and the client code.
    You can of course put other common functionality in the package (like a wrappers for the collections themselves, validation of names, etc.)

  • How to import outer classes into package inner classes?

    Hi, hope you all under stand my question. Sample as below:
    import A.*;
    public class ClassA{
        public ClassA{
            ClassB.CA = this;
    package A;
    public class ClassB{
         public static ClassA CA;  //Problem Here
    }As the sample above, i cannot declare public static ClassA CA in ClassB. Any way I can solve this? Can I import ClassA into package A? Thanks.
    Edited by: ocboon8 on Apr 6, 2008 6:50 AM

    A class that is in a package cannot access a class that is not in a package.
    db

  • Java.sql.Date and java.util.Date - class loaded first in the classpath

    I had two jar files which has java.util.Date and java.sql.Date class file. i want to know whether which class is loaded first in the classpath...
    I like to change the order of loading the class at runtime...
    Is there is any way to change the order of loading of class...
    I may have different version of jar files for example xerces,xercesImpl. some of the code uses xerces ,some of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according to the order i need..
    Can we do all these in Run time ?????

    I had two jar files which has java.util.Date and
    java.sql.Date class file. i want to know whether
    which class is loaded first in the classpath...
    I like to change the order of loading the class at
    runtime...
    Is there is any way to change the order of loading of
    class...
    I may have different version of jar files for example
    xerces,xercesImpl. some of the code uses xerces ,some
    of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according
    to the order i need..
    Can we do all these in Run time ?????That is meaningless.
    The classes you are referring to are part of the Java API. Third party jars have no impact on that. And you can't change to the order because java.sql.Data is derived from java.util.Date. So the second must load before the first.
    And if you have two jar files with those classes in them (and not classes that use them) then you either should already know how to use them or you should stop trying to do whatever you are doing because it isn't going to work.

  • Dependent class not found in the classpath

    Hi, Recently I was implemented a Class that implement "CallbackHandler".
    This class help me to build a security header for a SOAP Message, but when I execute this one in a OC4J, I obtain the next error:
    oracle.classloader.util.AnnotatedClassNotFoundException:
    Dependent class: oracle.security.wss.WSSecurity
    Loader: oracle.ws.security:10.1.3
    Code-Source: /E:/jdeveloper/webservices/lib/wssecurity.jar
    Configuration: <code-source> (ignore manifest Class-Path) in META-INF/boot.xml in E:\jdeveloper\j2ee\home\oc4j.jar
    This load was initiated at oracle.ws.security:10.1.3 using the Class.forName() method.
    The missing class is available from the following locations:
    I'm using JDeveloper 10.1.3.4. Any help?
    Edited by: user5540744 on 04-jul-2011 4:53

    Here is the work around:
    If you add the generated xxx_wsdl.jar to your buildpath in the ant build file, this warning goes away.

  • Importing a class file to change the Texture colour of a JFrame and JMenu?

    Well, my friend told me its possible, he has it on his Jframe, this is the code he uses;
    package theme;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.OceanTheme;
    public class BlackTheme extends OceanTheme
        public BlackTheme()
        public String getName()
            return "Black";
        protected ColorUIResource getPrimary1()
            return primary1;
        protected ColorUIResource getPrimary2()
            return primary2;
        protected ColorUIResource getPrimary3()
            return primary3;
        protected ColorUIResource getSecondary1()
            return secondary1;
        protected ColorUIResource getSecondary2()
            return secondary2;
        protected ColorUIResource getSecondary3()
            return secondary3;
        protected ColorUIResource getBlack()
            return black;
        protected ColorUIResource getWhite()
            return white;
        private final ColorUIResource primary1 = new ColorUIResource(33, 33, 33);
        private final ColorUIResource primary2 = new ColorUIResource(160, 160, 160);
        private final ColorUIResource primary3 = new ColorUIResource(77, 77, 77);
        private final ColorUIResource secondary1 = new ColorUIResource(0, 0, 0);
        private final ColorUIResource secondary2 = new ColorUIResource(51, 51, 51);
        private final ColorUIResource secondary3 = new ColorUIResource(100, 100, 100);
        private final ColorUIResource black = new ColorUIResource(20, 20, 20);
        private final ColorUIResource white = new ColorUIResource(125, 125, 125);
    }So how would i make it use that as the JFrame etc, because i tried like
    import theme.BlackTheme;and
    MetalLookAndFeel.setCurrentTheme(new BlackTheme()); but it dosn't re-colour it, am i doing something wrong? It only re-colours the actuall outside frame, not the main bits or menu bar as it is suppose to.
    Thanks

    Here are pictures of how the bar should look and what mine looks like.
    THIS IS WHAT MINE LOOKS LIKE
    [http://i166.photobucket.com/albums/u116/the_owner2007/menubaretc.jpg]
    This is how it should look correct...
    [http://i166.photobucket.com/albums/u116/the_owner2007/menubaretcblack.jpg]
    Edited by: i_own_pking on Apr 5, 2008 4:07 AM

  • Can we initiate a class without extending or importing that class or packag

    Can we invoke a class
    class dog
    public static void main(String args[])
    Animal a = new Aniamal();
    like this without extending or importing the package belongs to animal.

    Can we invoke a class
    class dog
    public static void main(String args[])
    Animal a = new Aniamal();
    like this without extending or importing the package
    belongs to animal.give it the package location
    class dog
      public static void main(String args[])
        org.mypackage.Animal a = new org.mypackage.Animal();
    }

  • Import class without package

    hellow, i have a web aplication named test , and i have a class named conexion
    when i import a package "pack" with the class conexion, not problem (test/WEB-INF/classes/pack/conexion.class) <% import="pack.* " %> but when i have only the class conexion WITHOUT package (test/WEB-INF/classes/conexion.class) and i import <%import ="conexion" %> i have problem ("The import conexion cannot be resolved") and when i not import the class i have problem (conexion cannot be resolved to a type) , my question is:
    how to i import a class without package in JSP , and if the test/WEB-INF/classes is in the classpath when compile the servlet , why the tomcat not found the class conexion?
    (tomcat 5.5.20 , jdk 1.5.09 , vim)
    thank
    (Sorry my english , i'm from Chile)

    Hi I am hosting my JSP application with Resin 2.17 which uses classes directly in JSP code (not packages). To make this work I had to specify the classpath in Resin.conf and it worked.
    My problem is getting this to work with TomCat or any other application server that will allow me to debug my project in Eclipse or NetBeans IDE. (I have yet to find an IDE that Supports debugging JSP/Java code running on Resin - so I want to switch my application server but I am not sure how to configure my classpath for the application servers to look for java classes in the specified directory just like I did with Resin.

  • Import  a class

    Hi all,
    i previuosly work with jbuilder 6 and i import a class (that locate in the project root directory and not include in any package) in the following way:
    import ClassName;
    and its compiled fine.
    when i start to work with Jbuilder2005 and also with netbeans,
    it refused to accept this kind of statment and im getting a compilation error.
    is any can suggest how can i import a class that has not include in any package.
    Thanks
    Gabi

    You can build classes without packages (in the default package). What you're seeing is a change in the definition of the import statement between 1.3 and 1.4. It's no longer permissable to have an import statement refering to a class without a package. The effect of this is that you can no longer refer to a class in the default package from a class in another package, because just giving the class name assumes a reference to the same package the reference is in.
    There's no problem when one class in the default package refers to another, you simply don't need the import statement.

  • Help! How to use a custom package (in the format of .JAR) in Forte4Java!

    Dear all,
    I am a beginner with Java. I have downloaded a Java package, jacob.jar, from the Internet. In order to import it in my Java program written under Forte4Java, I did the following stuff:
    1. Mount this JAR to the FileSystem; (this should include this package to the classpath, right?)
    2. Right-clicked the mounted JAR, and from the popup menu choose "Tool | Update Parser Database...";
    Next, I create a new Java project with a main class in it. At the head of this class file, I typed "import" to refer to this package. It turned out that the contextual completion window DOES show my package and all of its classes properly. In the body of this class file, I called some of the public methods defined in this package. The contextual completion window showed those methods properly too. Then I built this project and NO compilation error was reported. But, at run-time, an exception of "java.lang.UnsatisfiedLinkError: no jacob in java.library.path" was thrown at the invocation of the first public method of this package. I don't know what's happening here. Did I install the package the wrong way? If I can't get this problem solved as soon as possible, I will be in big big trouble :-( Please help and thanks in advance....
    FYI:
    the full exception message is as followed:
    java.lang.UnsatisfiedLinkError: no jacob in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1312)
    at java.lang.Runtime.loadLibrary0(Runtime.java:749)
    at java.lang.System.loadLibrary(System.java:820)
    at com.jacob.com.Dispatch.<clinit>(Dispatch.java)
    at testjacob.TestJACOB.main(TestJACOB.java:27)
    Exception in thread "main"
    Regards,
    Tracy

    I am not sure how exactly Forte works, so I don't know how useful my reply is, but here it is:
    Try checking the classpath manually that always helps. Your classpath should contain the directory in which the jar file is.
    Which OS are you using?

  • Classes without packages not accepted by ejbc compilation ?

    Hey guys ...
    I noticed something which I found unusual...I mite be missing something out here
    When ejbc generates the Bean IMPL class , it does not put any import statements
    in the generated java file but references all the classes in the Bean with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in packages...and
    I reference these classes within my Session Bean...the session bean compiles properly
    ..but when ejbc happens and the Impl class gets generated with the absolute path
    and no imports...the compiler expects to find all these 3rd-party classes without
    packages within the current session bean package itself which it will not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes without
    packages or is there something I am missing..?
    Thanx,
    Krish

    Rob ,
    I agree with u that giving classes without package is not a good practise..but
    Itz got a history which believe it or not stems from another weblogic problem(related
    to webservices..)
    anywayz..that is another issue alltogether...
    I don't think this bug is fixed...coz I checked a WLS70 Impl and it is still generating
    the IMPL without the imports...
    But can u clarify..what u wud mean by "fixing the bug" ..does it mean that the
    Impl would start putting the imports..?
    Thanx,
    Krish
    Rob Woollen <[email protected]> wrote:
    I recall this bug being reported before. You might try the latest
    service pack and see if it's been fixed already. Otherwise, you'll have
    to contact [email protected]
    FWIW, it's quite disturbing that a 3rd party would give you a jar
    without a package.
    -- Rob
    Krishnan Venkataraman wrote:
    Hey guys ...
    I noticed something which I found unusual...I mite be missing
    something out here
    When ejbc generates the Bean IMPL class , it does not put any import
    statements
    in the generated java file but references all the classes in the Bean
    with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in
    packages...and
    I reference these classes within my Session Bean...the session bean
    compiles properly
    ..but when ejbc happens and the Impl class gets generated with the
    absolute path
    and no imports...the compiler expects to find all these 3rd-party
    classes without
    packages within the current session bean package itself which it will
    not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes
    without
    packages or is there something I am missing..?
    Thanx,
    Krish

  • PDE-UJ1001, while trying to import java classes.

    Hi,
    When I try to import java classes into forms using the java
    importer, I get an error stating PDE-UJ1001-Failed to create
    JVM. I tried installing a patch in Developer 2000(Path 4a). But
    still it doesnt work. Could anybody guide me in this?
    Thanks,
    Karthick.

    am getting similar error - my dba has suggested that oracle developer uses the jvm from ie4 but i'm sure that cant be true as i thought the jvm was built in.
    could somebody out there clarify this or inform me whats missing..
    error
    from dev 6i forms builder (6.0.8.11.3) on 8i (8.1.7.2.0) when trying to select option 'import java classes' from program menu returns error 'PDE-UJ1001 Failed to create the JVM.'
    regards and thanks in anticipation....
    vin ferguson

  • Error While Importing Java Classes

    I have Forms 6i and when i am trying to import Java classes i am getting the following error
    "PDE-UJI001 FAILED TO START THE JVM".
    i think i have not set the path and classpath properly.i am having Windows 2000 server as my OS. please help me how to solve this problem

    The Java Importer tool needs the JDK 1.2.2 to be installed on
    the machine to run properly. This JDK can be downloaded from the
    Sun web site at http://www.sun.com
    If there is no JDK 1.2.2, the Java Importer tool cannot be started.
    Either that or its not being found in the classpath.
    Regards
    Grant Ronald
    Forms Product Management

Maybe you are looking for