Results 1 to 3 of 3
  1. #1
    PrinceSendai is offline Member
    Join Date
    Jul 2010
    Location
    Lima, Peru
    Posts
    47
    Rep Power
    0

    Default Importing classes in upper directory.

    MainClass.java
    graphics/Rectangle.java

    Java Code:
    public class MainClass{
    
    
    [INDENT]public String name;[/INDENT]
    
    }
    Java Code:
    package graphics;
    
    import MainClass;    //THIS IS THE ISSUE. 'IMPORT' REQUIRES A '.'
    
    
    public class Rectangle{
    
    ....
    [INDENT]MainClass c = new MainClass();
    c.name = x;[/INDENT]
    
    ....
    
    }
    I am trying to use main class within a package. I want to import MainClass, but MainClass is not in a particular package. It is simply in the upper directory. How do I import it?

    Also please let me know if this is not how I should be using the packages. Maybe I should place the MainClass in an actual package of its own?

    Thanks for the help.
    Prince

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Java Code:
    import graphics.Rectangle;

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Maybe I should place the MainClass in an actual package of its own?

    Yes, you should.

Similar Threads

  1. setting the "Java classes" directory in Linux
    By mr_anderson in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2010, 08:18 AM
  2. java run correctly in the upper directory
    By dangr in forum New To Java
    Replies: 1
    Last Post: 01-29-2010, 07:52 PM
  3. importing other classes or using a Jar
    By xhane in forum New To Java
    Replies: 3
    Last Post: 01-31-2009, 06:20 AM
  4. Need help with importing classes
    By Deathmonger in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 11:03 AM
  5. Importing classes
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-06-2007, 03:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •