• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error while compiling

 
Ranch Hand
Posts: 100
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 100
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic