Problem in importing a class

hi,
C:\sample:
My.java (this file is not a package and is directly inside the classpath)
c:\sample\mypackage:( the package is mypackage)
test.java extends My
Is it possible for a class in a package to extends from a class in the Classpath here in this case it is (C:\sample )
is it possible to give like this in the test.java
package mypackage
import My;
public class test extends My {
It is giving error :
. expected in import:
and without import it gives as Class not found error.
Is there any way to resolve this, ie referring a class outside the package
regards,
Deepa

well... that's not quite true... i did try out the
example with one class in no package, and a class ina
package that imports the first... and it works for
me... jdk1.4 too... the only problem is, i had toset
the path to the parent of the directory containingthe
first (no package) class...If I understand correctly, then this is news to Sun.
See item #8, second bullet.
http://java.sun.com/j2se/1.4/compatibility.html
ummm... sorry if i'm more 'Duh...' than usual (this is more than hangover!!!).... but the bulletted item refers to serializable classes... thatzz not what she's talking about... or is she..!??!
if i have a clas NoPackage.java in c:\dir1\dir2\NoPackage.java
and class HavePackage.java in c:\dir1\dir2\dir3\HavePackage.java, (with package named dir2.dir3)
i have my classpath set to c:\dir1.... and it works fine too.. sooooooo... what am i missing here.???

Similar Messages

  • Classpath problems when importing my classes

    I'm using a tutorial with sample programs dealing with bank accounts.
    I get this error:
    InterestBearingAccount.java [9:1] '.' expected
    import Account;
    ^
    1 error
    Errors compiling InterestBearingAccount.
    The Account class already exists in the current directory. I've tried everything as far as setting the classpath variable (nothing, just a period, period & slash, the actual complete path for the current directory, nothing works!!!!!). I also tried using -classpath (.) and the end of my javac command and that seemed to not work at all.
    The Java Coffee Break tutorial have some already compiled (*.class) files and they run fine. My *.java files are identical. In fact, I cut and pasted them so I know it's not a typo.
    My path is set to include the jdk1.4.0\bin directory and I've only begun to have problems now that I need to import existing classes into the programs.
    I should mention that I get the same error using Forte environment or doing it at the command prompt window. Please help.

    Thanks ATMGUY. I commented out the import statements in both InterestBearingAccount and AccountDemo and it worked fine. I guess the author of that tutorial was obviously not working with jdk 1.4.
    As far as using packages, com.kusek.bank would make a good package name then??
    The statement:
    package com.kusek.bank; OR a shorter version package kusek.bank;
    should be added to all three classes and no import statements would then be necessary, right??
    I just remember reading that it should be something unique as a good habit to get into.
    I'm trying to learn enough to make a useful GUI program for a special project so I probably should be using packages anyway when I get to that point.
    My programming backround is limited to procredural languages Basic, QBasic, Pascal, and Fortran and I find myself still wanting to think in those terms. I have read several web sites and worked through some basic examples but I still have much to learn. I once I can grasp how to write OOP style it would be nice to look at code for a somewhat detailed application (like a store checkout app) and have every line explained as to why it's there. I can see where it makes sense to have your GUI classes predefined (Swing), File I/O, serial port communications, and even things like this InterestBearingAccount example that extends from the Account class utilizing its basic attributes but overriding the constructors for the additional parameters (interest calculation) that are passed. How to take a common problem and go about creating a solution is what I need to see being done to help me.
    My telemetry project uses VHF radios with packet radio modems to monitor two diesel engines and turn one off if the other turns off. The modems have built in A/D data gathering and can also output control signals, they just need to be told what to do. I can manually use a Windows Hyperterminal session and type in "connect Engine1" and use commands to determine the A/D inputs "analog". The modems have built in end-to-end acknowledgement so the only think I need is an application than can be setup to run in the Startup folder to handle this. It would use a timer class to "poll" engine1 every 5-10 minutes and if it has stopped (based on the response of the "analog" command) I would "disconnect" from engine1 and "connect" to engine2 and send a "ctrl B off" or something similar. The standard responses from the modem should allow me just to send and recieve STRING data to and from the serial port and parse them as needed. I need at least this much but it shouldn't be too much harder to develop a way to reset the system(reverse of this) when that is required. I could also read a water pressure value at one of the locations and display that on the screen along with the current status of the engines (using values obtained from the "analog" command on the modems).
    The hardest part of OOP programming seems to be knowing what classes are already out there and knowing how to find them or apply them. I hope Swing has classes that provide for displaying values on the Windows taskbar (my motherboard monitor freeware displays temperature readings down on the taskbar). I appreciate all the help given here. It's almost like having a private tutor.
    randy

  • Problem When Import Java Class -compilation error

    Hi all
    I made a java class that has methods to return Screen width and Height .
    package tarek;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    public class Screen
    Dimension dim ;
    public Screen()
    dim = Toolkit.getDefaultToolkit().getScreenSize();
    public double getWidth()
    double w = dim.getWidth();
    return w;
    public double getHeight()
    double h=dim.getHeight();
    return h;
    I made the jar file " screen.jar" and make it ready to use in form builder
    I opened form builder and make import java class (From program>import java class>choose the class anc click import)
    The class now imported successfully and the PL/SQL package body is:
    PACKAGE Screen /* tarek.Screen */ IS
    -- DO NOT EDIT THIS FILE - it is machine generated!
    -- Constructor for signature ()V
    FUNCTION new RETURN ORA_JAVA.JOBJECT;
    -- Method: getHeight ()D
    FUNCTION getHeight(
    obj ORA_JAVA.JOBJECT) RETURN NUMBER;
    -- Method: getWidth ()D
    FUNCTION getWidth(
    obj ORA_JAVA.JOBJECT) RETURN NUMBER;
    END;
    Now I made a button on the form and i WRITE THIS CODE TO INVOKE THE CLASS on when_button_pressed
    DECLARE
         vScreen_Class ORA_JAVA.JOBJECT;     
    BEGIN
         vScreen_Class := SCREEN.NEW;
    END;
    My problem is I have compilation error
    error 306 AT LINE 5 , COLUMN 25
    wrong number or types of argument in call to "NEW"
    I do not know what is the reason of this compilation error?
    Is it because the method in java return "double datatype" while in oracle return "number datatype"
    Please help
    Edited by: [email protected] on Dec 28, 2009 10:24 AM

    Sarah, I ca not move my thread to JDeveloper because it is not java issue. The problem is with my PL/SQL code and the way I make Import Java class to forms Builder. The Java code is OK.
    Andreas Thank you so much for replying. In fact I made a full compile "Ctrl+Alt+K". but still error
    The following is the package Body
    PACKAGE BODY Screen IS
    -- DO NOT EDIT THIS FILE - it is machine generated!
    args JNI.ARGLIST;
    -- Constructor for signature ()V
    FUNCTION new RETURN ORA_JAVA.JOBJECT IS
    BEGIN
    args := NULL;
    RETURN (JNI.NEW_OBJECT('tarek/Screen', '()V', args));
    END;
    -- Method: getHeight ()D
    FUNCTION getHeight(
    obj ORA_JAVA.JOBJECT) RETURN NUMBER IS
    BEGIN
    args := NULL;
    RETURN JNI.CALL_DOUBLE_METHOD(FALSE, obj, 'tarek/Screen', 'getHeight', '()D', args);
    END;
    -- Method: getWidth ()D
    FUNCTION getWidth(
    obj ORA_JAVA.JOBJECT) RETURN NUMBER IS
    BEGIN
    args := NULL;
    RETURN JNI.CALL_DOUBLE_METHOD(FALSE, obj, 'tarek/Screen', 'getWidth', '()D', args);
    END;
    BEGIN
    NULL;
    END;
    ---------------------------------------------------------------------------------

  • Problem in import a class

    Hi,
    I have downloaded the ver j2sdk1.4.2. I faced a problem when compiler my program. The problem seems because of import class JOptionPane, JAppet, Graphics in my program. Does anybody can advise how to resolve this problem?
    Error"
    Welcome2.java:6: cannot resolve symbol
    symbol : class Graphic
    location: class Welcome2
    public void paint (Graphic g )
    ^
    Best Regards
    Fiyona

    Thanks for the alert. The program is completed compile. Unlucky, there again error when try to run it. I knew my program very simple. But it always comes out with error when i use an IMPORT CLASS. Can anybody help?
    import javax.swing.JApplet;
    import java.awt.Graphics;
    public class Welcome2 extends JApplet{
    public void paint (Graphics g )
         g.drawString("WElcome!", 25, 25);
    error:
    C:\j2sdk1.4.2_08\bin>java Welcome2
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Regards
    Fiyona

  • Problem with importing a class

    When I compile my class, I get an error pointing to the import statement saying that it expects a period. Below is my code followed by the error I get:
    import Entry;
    public class Dictionary2 extends Entry
      protected Entry entries[];
      public Dictionary2(String puzzle)  // constructor
        entries = new Entry[5];
        if (puzzle == "unscramble")
          entries[0].setEntry("stupid", "Insult");
          entries[1].setEntry("monkey", "Zoo animal");
          entries[2].setEntry("meerkat", "Cute furry African animal that stands 12 inches high on its hind legs");
          entries[3].setEntry("burrow", "Where meerkats sleep and raise their pups");
          entries[4].setEntry("boogers", "Gross things");
    }C:\Program Files\Java\jdk1.6.0_01\bin>javac Dictionary2.java
    Dictionary2.java:1: '.' expected
    import Entry;
    ^
    1 error
    There is nothing wrong with my Entry class. It's where it's supposed to be, and it's compiled correctly. Why is it wanting a period? Your help will be greatly appreciated.

    SysterTara wrote:
    What I'm talking about is this: When you use a package, you have to create a directory path on your hard drive, like com\mydomain\project\Entry. When you want to upload it to a website, what do you do? Will it not work anymore? Will you have to create com/mydomain/project/Entry on the website? Please forgive my lack of knowledge. I am very inexperienced.You're confusing the classpath with your package structure.
    Packages are used to organize Java classes. You import classes based on their fully-qualified name, including the package they belong to. Packages are location-independent.
    The classpath is how the Java VM finds all the classes you're using. When you run a java program, you supply a list of paths to package roots and jar files, which the VM will use as a starting point to find the classes you've imported.

  • Having problems with importing a class

    I'm getting this error:
    Main.java:14: Class Queue not found in import.
    import Queue;
    ^
    1 error
    The two files are Queue.java and Main.java. Queue.java compiles fine. I get this error when i try to compile Main.java. I have no idea why it is doing it. This is Queue.java:
    import java.io.*;
    public class Queue{
    private int MAX=0;
    private String[] projectlist;
    // Constructors
         public Queue() {
              projectlist = new String[MAX];
         public Queue (int size) {
              MAX = size;
              projectlist = new String[MAX];
         public void Print() {
              System.out.println(MAX + "\n");
    And this is Main.java:
    import java.io.*;
    import Queue;
    public class Main {
    public static void main(String[] args)     {
         Queue high = new Queue(2);
         Queue highwait = new Queue();
         Queue medium = new Queue(5);
         Queue low = new Queue(8);
         Queue lowwait = new Queue();
         high.Print();
         highwait.Print();
         medium.Print();
         low.Print();
         lowwait.Print();
    I sent the files to a friend, and he got the same error, so is it something to do with the actual file? Any help would be greatly appreciated, because if I can't get this working, I gotta do the project in C++, which i don't want to do :)This is on Linux, BTW. Thanks!

    Ok lets go through this step by step.
    First, somewhere in your path you have a directory called 'queue' and in it is a java file 'Queue.java'. On my computer, I have this directory in
    '/home/joshua/development/java/test'. From the directory 'queue' the command
    $javac Queue.java
    should compile.
    Does that compile?
    In '/home/joshua/development/java/test' I also have the java file 'Main.java', which compiles, without error, with the command
    javac Main.java
    Does that compile?
    Queue.java needs the statement
    package queue;
    And Main.java needs the statement
    import queue.Queue;
    I will post my modified code or help you adjust your Classpath if this does not work, because it is working fine on my comp.

  • Importing Java class problem!

    Hello
    I have problem by Importing java class into form. When I select in Forms Builder from menu: Programs/Import Java Classes it returns error: PDE-UJI001 JVM not able to create!
    Can someone know what I must do to fix that problem?
    Thanks, Chrity

    It is a shame because it, probably, contains no special 1.5 new instruction at all.
    Maybe it would be possible to try replacing the current JDK/JRE of your <ORACLE_HOME>/jdk installation after a safe backup of course.
    You probably have a very little chance that it works, and it also won't be supported.
    Francois

  • Problems importing a class with inner class

    Why can't I import a class so that I can use an (inner) static member class without naming the enclosing class. Put simply, I have:
    file C:\MyJava\Test\A:
    public class A {
      public static class B { }
    }file C:\MyJava\Test\C
    import A.*;
    public class C { }When I try to compile C (javac -classpath C:\MyJava\Test;. C.java) it fails with C.java:1: package A does not exist

    Class A must be in a package if you wish to import it. If you want to use the inner class, just import somepackage.A. You could then refer to A.B...
    HTH :o)

  • Problems importing servlet classes

    When I try to compile a bean which has import statements for importing servlet classes, I get the message that the class is not found in import when I compile the code. I have all these class files and I'm not sure whether I've placed them aptly. Please give me the details about placing the servlet classes and configuring my javac to import these classes.
    Thanks!

    If you place your classes in the %JAVA_HOME%/jre/lib/ext, they will be automatically accepted by the javac and the java. But, depending on the classes you use, it would be better to include them in %application path%/WEB-INF/lib, so they will only be used by that application.

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • A  classpath error while  importing a class with @page import property

    Hi ,
    I am using Tomcat contaniner for jsp applications. I have developed a page that i have import a class. when i use
    <%@ page import="myclass" &>
    i got an error that myclass not found. I have placed into tomcat\webapps\myproject\web-inf\classes directory. So How will I set the classpath for myclass to work?
    thanks.

    I was able to simulate your problem when I created a mismatch in the case of the name of the class.
    for example if my program is called MyClass.java
    and in the import I do <@page import="myclass" %>
    Are you sure about the case of class name that you are using? Please check that the file is called myclass.java the class defined inside it is called myclass and the class file that is copied into the WEB-INF/classes directory is also myclass.class. There should be no difference in the case of the names. like MyClass.java or MyclaSS.class
    Other things to check are
    1. If myclass is defined in a package then you have to import with the package.
    2. Make sure that your jsp is located in the myprojects directory and the class file is copied under myprojects/WEB-INF/classes.
    Let me know if things still don't work
    regards,
    Abhishek.

  • Problem in importing JavaClass in oracle forms

    Hi gurus,
    I
    I am using
    Forms [32 Bit] Version 10.1.2.0.2 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
         With the Partitioning, OLAP and Data Mining options
    Oracle Toolkit Version 10.1.2.0.2 (Production)
    PL/SQL Version 10.1.0.4.2 (Production)I am trying to import java Class into forms builder. I am doing this for the first time .
    for this I have done...........
    I made a simple class in jDeveloper for practice with simple output line
    public class getSystem {
         public String var ="thistext";
         * @param args the command line arguments
        public String get_text() {
         return this.var;
        public static void main(String[] args) {
           System.out.println("this is test");
    }then I made this file as SAM.JAR (using deploying methode)
    set directory path of this SAM.JAR forms_builder_path in regedit,
    then import this class in form builder using program > import java class
    have the following code in program units
    PACKAGE getSystem /* getSystem */ IS
      -- DO NOT EDIT THIS FILE - it is machine generated!
      -- Constructor for signature ()V
      FUNCTION new RETURN ORA_JAVA.JOBJECT;
      -- Method: main ([Ljava/lang/String;)V
      PROCEDURE main(
        a0    ORA_JAVA.JARRAY);
      -- Method: get_text ()Ljava/lang/String;
      FUNCTION get_text(
        obj   ORA_JAVA.JOBJECT) RETURN VARCHAR2;
    END;-----------------------------------------------------------------------
    PACKAGE BODY getSystem IS
      -- DO NOT EDIT THIS FILE - it is machine generated!
      args   JNI.ARGLIST;
      -- Constructor for signature ()V
      FUNCTION new RETURN ORA_JAVA.JOBJECT IS
      BEGIN
        args := NULL;
        RETURN (JNI.NEW_OBJECT('getSystem', '()V', args));
      END;
      -- Method: main ([Ljava/lang/String;)V
      PROCEDURE main(
        a0    ORA_JAVA.JARRAY) IS
      BEGIN
        args := JNI.CREATE_ARG_LIST(1);
        JNI.ADD_OBJECT_ARG(args, a0, '[Ljava/lang/String;');
        JNI.CALL_VOID_METHOD(TRUE, NULL, 'getSystem', 'main', '([Ljava/lang/String;)V', args);
      END;
      -- Method: get_text ()Ljava/lang/String;
      FUNCTION get_text(
        obj   ORA_JAVA.JOBJECT) RETURN VARCHAR2 IS
      BEGIN
        args := NULL;
        RETURN JNI.CALL_STRING_METHOD(FALSE, obj, 'getSystem', 'get_text', '()Ljava/lang/String;', args);
      END;
    BEGIN
      NULL;
    END;----------------------------------------
    I made a simple form having one button , on when-button-pressed trigger I wrote this code
    declare
           Jvar ORA_JAVA.JOBJECT;
           Fvar varchar2(100);
           ex varchar2(5000);
           javaException ORA_JAVA.JOBJECT;
    begin
           Jvar := getsystem.new();
           Fvar := getsystem.get_text(Jvar);
           message('this is outcomes from java'||Fvar);
    EXCEPTION
           WHEN ORA_JAVA.EXCEPTION_THROWN THEN
             message('Java Exception');
           WHEN others THEN
             message(sqlerrm);
       END;---------------------------
    it shows me message 'java Exeption' which means something is wrong ....
    when I used this code taken from form builder's help
    EXCEPTION
           WHEN ORA_JAVA.EXCEPTION_THROWN THEN
             javaException := ORA_JAVA.LAST_EXCEPTION;
             -- Print out the Exception by using the toString()
                -- Method of the exception Object
             message(Exception_.toString(javaException));
          -- and clean up
          ORto catch the exception it shows toString must be declared.....
    once I know how to get the value of java methods on forms I could countinue my practices using java on forms please guide me
    thanks

    thanks for you kind replies Sir,
    Craig Sir now it's working very well for me , now I can get and set the values of variables and as well as methodes
    the problem was solved ,
    Andreas Weiden Sir your was right I didn't set the classPath setting in .ENV file , thanks a lot ..
    these are the points I really wanna share  for those  who'll ever face the same problem..
    (1) made simple class in Jdeveloper
    public class getSystem {
         public String varibless ="thistext";
         * @param args the command line arguments
        public int get_text(int bc) {
         int a = 5;
         int b= 10;
         return bc+a;
        public static void main(String[] args) {
           getSystem  var2 = new getSystem();
           System.out.println(var2.get_text(5));
    }make it .jar file using deploying mathode...
    (2) set FORMS_BUILDER_CLASSPATH in regedit..
    (3) restart forms builder and go to progarm > import java class
    (4) select the class name that you made
    (5) press option button and check include get/set public fields if you wanna interact with variables in class
    (7) now make simple canvas with button , us this code on when-new-button press trigger
    declare
           Jvar ORA_JAVA.JOBJECT;
           Fvar varchar2(100);
           ex varchar2(5000);
           javaException ORA_JAVA.JOBJECT;
           --mn ORA_JAVA.JARRAY(10);
    begin
           jvar := getsystem.new;      
           Fvar := getsystem.get_text(Jvar,5);
           message('this is outcomes from java'||Fvar);
           ex   := getsystem.getvaribless(jvar);
           message('value of the variable in class  '||ex);
              --- similerty change the value of variable in class and then get it again
             getSystem.setvaribless(jvar,'yournewvalue');
    EXCEPTION
           WHEN ORA_JAVA.java_error THEN
             message( ora_java.last_error);
           WHEN others THEN
             message(sqlerrm);
    END;hope for the best.....
    thanks a lot again...
    regards:
    usman noshahi

  • Import packageless classes in a jsp : tomcat 5.0.16

    Hi all,
    I am trying to import a class, say one.class, which is stored in the /WEB-INF/classes folder of the webapplication into a jsp page. Like,
    <%@page import="one"%>
    I get the following error,
    C:\jakarta-tomcat-5.0.16\work\Catalina\localhost\test\org\apache\jsp\testing_jsp.java:7: '.' expected
    import one;
    what could the problem be? I suppose, the problem is in accessing a class which is not inside a jar.
    take care,
    Siddharth.

    Hi,
    If you are using jdk 1.4 and above, you need to have package name for classes .
    You could just give a try after removing the import statement . Perhaps the server could find the classes in your WEB-INF/classes directory. I doubt though.
    -Amol

  • How to import a class, which is not in a package?

    Hi all,
    I have the following problem:
    A class A is not in a package. In another class B, which is in a package (let's say package X) I want to use the class A. Without importing the class A, I get the error "Cannot resolve symbol".
    Using the import statement import A; gives the error ". expected".
    How can I import that class?
    Best wishes to all ...
    Heiko

    > I have the following problem:
    A class A is not in a package. In another class B,
    which is in a package (let's say package X) I want to
    use the class A. Without importing the class A, I get
    the error "Cannot resolve symbol".
    I think not putting a class in a package is a bad practice. Avoid that.

  • Problem in importing package

    i am new to java and facing problems in importing package which are self made.
    secondly does JDK 1.1.3 can support swing

    Hi,
    I had some problems myself. I will add few lines, maybe it helps:
    OK, let's assume that you work in a directory. In this case, set classpath to this hierarchy as well as to "." ('this' hierarchy - like in DOS).
    Now, assume that you want to use packages MyPack1 and MyPack2. The source files of classes belonging to MyPack1 must:
    - start with command
    package MyPack1;
    - be located all in the directory MyPack1
    (and the same for MyPack2, of course)
    If you want to use MyPack1 within MyPack2, you have to include:
    import MyPack1.*;
    even though MyPack1 is, in fact, located on path: ../MyPack1/*
    (trust the classpath is important here)

Maybe you are looking for