This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error while compiling

 
Varshini Priya
Ranch Hand
Posts: 95
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Varshini Priya
Ranch Hand
Posts: 95
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic