wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes error while compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error while compiling " Watch "error while compiling " New topic
Author

error while compiling

Varshini Priya
Ranch Hand

Joined: Feb 17, 2008
Posts: 93

Hi

Im trying to compile the below program, but im not able to do it. Im getting the below error.

mycode is

[code]

import pack1.*;
import pack1.pack2.*;
class Result
{
public static void main(String [] args)
{
class1.a = new class1();
class2.b = new class2();
a.getname();
b.putnum();
}
}
[\code]

when i try to compile this, i get the below error

C:\Program Files\Java\jdk1.5.0_09\bin>javac Result.java
Result.java:1: package pack1 does not exist
import pack1.*;
^
Result.java:2: package pack1.pack2 does not exist
import pack1.pack2.*;
^
Result.java:7: cannot access class1
bad class file: .\class1.class
class file contains wrong class: pack1.class1
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
class1.a = new class1();
^
3 errors

Please help me understand why im receiving the error.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by Varshini Priya:
[Q]
C:\Program Files\Java\jdk1.5.0_09\bin>javac Result.java
Result.java:1: package pack1 does not exist
import pack1.*;
^
Result.java:2: package pack1.pack2 does not exist
import pack1.pack2.*;
^
Result.java:7: cannot access class1
bad class file: .\class1.class
class file contains wrong class: pack1.class1
Please remove or make sure it appears in the correct subdirectory of the classpath.
class1.a = new class1();
^
3 errors

Please help me understand why im receiving the error.[/Q]


The errors are self explanatory,

For first two errors ,
you provided an non existing or non reachable packages. Make sure that the package you are defining resides in CLASSPATH !!

For third error,
You can't define an object like this, with DOT . operator!



Hope this Help !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Varshini Priya
Ranch Hand

Joined: Feb 17, 2008
Posts: 93

Hi

The packages are exisiting in the same path as that of the Result.java class. I mean to say that the path of the packages and the Result.java are in the location C:\Program Files\Java\jdk1.5.0_09\bin>.Im not sure how to set the classpath since both the package and the class file are residing in the same location
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Don't put your work in the /bin folder. Create a Java folder elsewhere, and put your work in that.

Do a search for similar threads; this problem comes up frequently; here is one which might help. This one, too.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The PATH and CLASSPATH are two different things, first find the executable and later finds the supported class require to run code!

Now, If you have Result.java in this directory "C:\Program Files\Java\jdk1.5.0_09\bin>"

then there must be a directory named pack1 , inside which there is second directory named pack2.

If this two packages(directory) are there, then try to compile as



Else, make those directory structure and places the respective complied .class file into it and then compile !!

May be you learn from this and OR this first !!

HTH
 
jQuery in Action, 2nd edition
 
subject: error while compiling
 
Similar Threads
Issue when compiling a class which is importing a package
dumb qn on Packages
package problem
package trouble
Trouble with packages.