Results 1 to 5 of 5
  1. #1
    Sagars is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default Package Doesn't exist - Issue with import

    It's very simple problem but I never understood why I am getting error

    This is the existing scenario mentioned in 1.
    1. I have 2 files suppose name is Sample.java and Hello.java - At location com.XXX.ABC



    Sample.java -

    package com.XXX.ABC

    public class Sample
    {

    Hello.log("nothing");


    }

    Hello.java -

    package com.XXX.ABC

    public class Hello
    {

    public static void log(String msg)
    {
    System.out.println(msg);
    }


    }


    2. I want to move the Hello.java file to package DEF i.e com.XXX.ABC.DEF
    so if I want to get the content of Hello file like below with importing the Hello package it should work right?

    Sample.java -

    package com.XXX.ABC

    import com.XXX.ABC.DEF.*; ===> Added this line

    public class Sample
    {

    Hello.log("nothing");

    }


    [javac] package com.XXX.ABC.DEF does not exist
    [javac] import com.XXX.ABC.DEF.*;
    [javac] ^
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error


    I tried this scenario in eclipse and it's working fine it's very simple move the file and it will update automatically but
    when I am trying this on linux box it's giving package not found error.. Can someone plz explain what is real issue?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    What paths are in the classpath when you try to compile the program?
    Does the package path exist?

  3. #3
    Sagars is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default

    when I ran the file Sample.java in first scenario - that mean both files present at same location i.e com.XXX.ABC
    so that mean it's working for that path.

    After that I just did added one folder DEF under ABC i.e com.XXX.ABC.DEF and imported that in Sample.java.

    Sample.java -

    package com.XXX.ABC

    import com.XXX.ABC.DEF.*; ===> Added this line

    public class Sample
    {

    Hello.log("nothing");


    }


    So do we need to setup a classpath for this ...if yes then how do I find that classpath.?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    Can you post the code you are compiling? What you posted would not compile.
    Can you open a command prompt and enter the javac command you are using and also enter a dir command to show the contents of the folder and also enter the SET command to show the classpath?
    Copy and paste the console contents here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  5. #5
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default

    You can use -d option with with javac command to direct the compiler to automatically create folder hierarchy for you to the path specified by you.
    For eg:
    Java Code:
    >javac -d <pathToPlaceClassFiles> *.java
    You can also use -cp option to provide the classpath(the folder containing your "com" folder ) to the compiler.

Similar Threads

  1. package jxl does not exist ??? any ideas
    By Macca07 in forum New To Java
    Replies: 5
    Last Post: 05-14-2012, 08:38 PM
  2. org.apache.hadoop package is not exist
    By ubu@ in forum Eclipse
    Replies: 1
    Last Post: 04-24-2011, 01:34 PM
  3. package does not exist error
    By glaze24 in forum New To Java
    Replies: 1
    Last Post: 11-28-2010, 03:03 PM
  4. getImage - not fail when image doesn't exist
    By leonid.ge in forum Java Applets
    Replies: 0
    Last Post: 07-24-2009, 04:17 PM
  5. package mj does not exist
    By PzK in forum New To Java
    Replies: 8
    Last Post: 12-03-2008, 11:30 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
  •