Page 1 of 2 12 LastLast
Results 1 to 20 of 28
Like Tree1Likes

Thread: Javac Compiler Error[import package]

  1. #1
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Javac Compiler Error[import package]

    I need ur help friends... i m getting error when compiling a small java program....
    i hav two java file..

    location

    1:-E:\Demo\org\dpk\first.java
    2:-E:\Demo\org\helper\second.java

    source code of first.java:-[When i compile this i got import package error line 2 & 5 [symbol not found]]
    command[E:\Demo\org\dpk>javac first.java -classpath "E:\Demo\org\helper\helper.class"]
    command[E:\Demo\org\dpk>javac first.java -classpath E:\Demo\org\helper\helper.class]
    command[E:\Demo\org\dpk>javac first.java -classpath E:\Demo\org\helper]

    package org.dpk;
    import org.helper;-----error
    public class first{
    public static void main(String[] args){
    second s=new second();------error
    int result=s.call(5,2);
    System.out.println("The Number is : "+result);
    }
    }


    source code of second.java:-[this file compiled succesfully][E:\Demo\org\helper>javac second.java]

    package org.helper;
    public class second{
    public int call(int a, int b){
    int c=a+b;
    return c;
    }
    }

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

    Default Re: Javac Compiler Error[import package]

    You should set the classpath to the folder containing the org folder. The classpath + the package path is used to find the class definitions.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    i already set with javac command... wt about package path... how to set it... actually javac compiler unable to find the classpath thats why givind this package import error...
    [E:\Demo\org\dpk>javac first.java -classpath "E:\Demo\org\helper\helper.class" ...

    cal u please help me what command i fire to compile first.java file...

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,764
    Blog Entries
    7
    Rep Power
    21

    Default Re: Javac Compiler Error[import package]

    No, set your classpath to the value E:\Demo; the compiler will figure out the reset given the package names.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    Does the classpath for the javac command point to the folder containing the org folder?

    Post the contents of the command console window for when you execute the javac command.
    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.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    Javac Compiler Error[import package]-deepakkkk.jpg

  7. #7
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    JosAH ... i have tried it classpath to the value E:\Demo; still same package not found error.....

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    Post the console contents for when you get the error.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    i have posted the console content

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    tried it classpath to the value E:\Demo
    Where is the console where you set the classpath to the Demo folder?
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    Javac Compiler Error[import package]-try.jpg

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    actually the error concept is same... here i got problem to compile a simple java file.... and in another thread having problem to compile servlet... same error import package error.....

  14. #14
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    i tried everything... every option with javac ..... i dont know where is the problem... i'm just calling the method of another class.. so i just import the package... and also set the classpath then what is the another problem ..... is there any problem with JDK...?

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    This will be the thread to use from now on.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default Re: Javac Compiler Error[import package]

    The classpath must point to the folder that contains the folder that is the start of the package path.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Javac Compiler Error[import package]

    Use an uppercase letter at the start, and a single punctuation mark at the end of each sentence and more people might read your posts.

    What do you hope to gain with all the .... ..... ..... anyway? Do you think the long chains of periods look pretty?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Javac Compiler Error[import package]

    The command with the '-cp E:/Demo' is correct.
    The problem is this:
    Java Code:
    import org.helper;
    You don't import packages in Java, you import classes.
    You can indicate you want to import all classes in a package by using the wildcard '*'.
    SO the above should be one of:
    Java Code:
    import org.helper.<your class name>;
    import org.helper.*;
    The first one is the preferred style.
    pateldpk likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,764
    Blog Entries
    7
    Rep Power
    21

    Default Re: Javac Compiler Error[import package]

    The syntax for the compiler is javac <options> <source files>; not the other way around so your classpath setting should come before the source file name.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    pateldpk is offline Member
    Join Date
    Apr 2012
    Posts
    27
    Rep Power
    0

    Default Re: Javac Compiler Error[import package]

    @Tolls...I tried
    import org.helper.second;
    Or
    import org.helper.*;
    still getting same error....

    @JosAH.... I tried both syntax ...Classpath before source file AND Classpath after source file.... Still same error....
    Last edited by pateldpk; 04-12-2012 at 08:06 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 22
    Last Post: 02-10-2012, 01:41 PM
  2. Netbeans (demo) "Unable to find a javac compiler
    By pottzie in forum New To Java
    Replies: 0
    Last Post: 10-25-2011, 11:52 PM
  3. Compiler runtime package load error
    By Dark-Redd in forum Advanced Java
    Replies: 17
    Last Post: 10-09-2011, 10:21 AM
  4. javac compiler
    By krishk in forum New To Java
    Replies: 2
    Last Post: 07-15-2010, 07:09 PM
  5. javac does not import package from jar in 1.6
    By tonydr in forum Advanced Java
    Replies: 0
    Last Post: 05-26-2010, 11:34 PM

Posting Permissions

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