Results 1 to 20 of 28
- 04-12-2012, 12:44 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
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;
}
}
- 04-12-2012, 01:37 PM #2
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.
- 04-12-2012, 01:55 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
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...
- 04-12-2012, 01:58 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-12-2012, 01:58 PM #5
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.
- 04-12-2012, 02:07 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
- 04-12-2012, 02:13 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
Re: Javac Compiler Error[import package]
JosAH ... i have tried it classpath to the value E:\Demo; still same package not found error.....
- 04-12-2012, 02:21 PM #8
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.
- 04-12-2012, 02:24 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
Re: Javac Compiler Error[import package]
i have posted the console content
- 04-12-2012, 02:25 PM #10
Re: Javac Compiler Error[import package]
Where is the console where you set the classpath to the Demo folder?tried it classpath to the value E:\DemoIf you don't understand my response, don't ignore it, ask a question.
- 04-12-2012, 02:26 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
- 04-12-2012, 02:27 PM #12
Re: Javac Compiler Error[import package]
Why are there two threads for this?
import package error...... calling method of another java class from servlet...If you don't understand my response, don't ignore it, ask a question.
- 04-12-2012, 02:29 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
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.....
- 04-12-2012, 02:33 PM #14
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
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...?
- 04-12-2012, 02:36 PM #15
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.
- 04-12-2012, 02:39 PM #16
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.
- 04-12-2012, 02:39 PM #17
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-12-2012, 02:50 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Javac Compiler Error[import package]
The command with the '-cp E:/Demo' is correct.
The problem is this:
You don't import packages in Java, you import classes.Java Code:import org.helper;
You can indicate you want to import all classes in a package by using the wildcard '*'.
SO the above should be one of:
The first one is the preferred style.Java Code:import org.helper.<your class name>; import org.helper.*;
Please do not ask for code as refusal often offends.
- 04-12-2012, 03:14 PM #19
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-12-2012, 07:03 PM #20
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
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 07:06 PM.
Similar Threads
-
javac cannot compile my source which uses a package
By jpocok in forum New To JavaReplies: 22Last Post: 02-10-2012, 12:41 PM -
Netbeans (demo) "Unable to find a javac compiler
By pottzie in forum New To JavaReplies: 0Last Post: 10-25-2011, 10:52 PM -
Compiler runtime package load error
By Dark-Redd in forum Advanced JavaReplies: 17Last Post: 10-09-2011, 09:21 AM -
javac compiler
By krishk in forum New To JavaReplies: 2Last Post: 07-15-2010, 06:09 PM -
javac does not import package from jar in 1.6
By tonydr in forum Advanced JavaReplies: 0Last Post: 05-26-2010, 10:34 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote![Javac Compiler Error[import package]-deepakkkk.jpg](http://www.java-forums.org/attachments/new-java/3543d1334232471t-javac-compiler-error-import-package-deepakkkk.jpg)
![Javac Compiler Error[import package]-try.jpg](http://www.java-forums.org/attachments/new-java/3546d1334233331t-javac-compiler-error-import-package-try.jpg)

Bookmarks