• 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

JDate not found in JDateTest

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam sure this is an obvious problem but I have a class, JDateTest that tries to create a new JDate object but it cant seem to access the JDate class. Both JDate and JDateTest are both in the same folder.

I've tried "import com.javaranch.common.*;" but this still gives :

JDate not found in JDateTest

Heres the class, thanks:





public class JDateTest{


public static void main(String args[]){



JDate test = new JDate(2000,2,20);

System.out.println(test.get());


}//end main

}//end class JDateTest
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephen,
Welcome to JavaRanch!

When you try to compile them, use:
javac *.java

The JDK will find them if both are compiled in the same shot.

[edited to fix typo]
[ July 22, 2005: Message edited by: Jeanne Boyarsky ]
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne!
Do you mean like : javac JDate.java JDateTest.java ?
I tried this and got:
JDateTest.java cannot access JDate
bad class file: .\JDate.class
class contains wrong class: com.javaranch.common.JDate
please remove or make sure it appears in the correct subdirectory of the classpath

The JDate class compiles fine on its own.

I know such a simple error must seem daft -thanks for your help
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stephen Connery:
Thanks Jeanne!
Do you mean like : javac JDate.java JDateTest.java ?
I tried this and got:
JDateTest.java cannot access JDate
bad class file: .\JDate.class
class contains wrong class: com.javaranch.common.JDate
please remove or make sure it appears in the correct subdirectory of the classpath

The JDate class compiles fine on its own.

I know such a simple error must seem daft -thanks for your help



I think Jeanne meant exactly what she said. You should type "javac *.java". Of course, I think the way you have done it should work, too. It sounds like the problem may be a directory and classpath issue. Can you please describe the directory structure that contains the two files for these classes? Which directory are you in when you try to compile? And have you set the CLASSPATH environment variable on your machine? If so, what is it?
Answers to these questions will help us figure out what you need to do to fix your problem.

Layne
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to include the JavaRanchCommon.jar (old) or jr.jar (current) which contains the JDate class in your classpath before you can import any classes from it.

The JDate is already compiled inside the jar. You don't need to recompile it.
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Layne and Marilyn de Queiroz!

My (Path)classpath is set to:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;c:\j2sdk1.4.1\bin

I got the JDate class from the jr.jar file.

I added c:\Jfiles\jr.jar to the path variable like:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;c:\j2sdk1.4.1\bin;c:\Jfiles\jr.jar

And added : import com.javaranch.common.*; to the JDateTest class

Both classes JDate and JDateTest are in:

c:\Jfiles\code

This is where I compiled them from.

But still get the error:

JDateTest.java cannot access JDate
bad class file: .\JDate.class
class contains wrong class: com.javaranch.common.JDate
please remove or make sure it appears in the correct subdirectory of the classpath

Thanks for your help
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


please remove or make sure it appears in the correct subdirectory of the classpath



This error message is right on target. You have the JDate class in your current directory, where it shouldn't be. It should be in a subdirectory called "com.javaranch.common", but actually, since you include the jr.jar file in your classpath, it shouldn't even be there. Just delete it, and things should be fine.
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

I deleted JDate from the c:\Jfiles\code folder and it worked! Iam not too sure though why this worked. Did this work because the jr.jar file was included in the classpath or because the JDate class was in the c:\Jfiles\code\com\javaranch\common folder?

When you want to include a class where does that class have to be stored and is it different if the class is part of a package or in a jar file?


Cheers
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should do either one or the other. Either extract the class and put it in the c:\Jfiles\code\com\javaranch\common subdirectory or include the jar in your classpath. Not both.

By the way, I would recommend removing the c:\j2sdk1.4.1\bin from your CLASSPATH. Although it should be in your PATH, you should avoid putting any of your own code into that directory.
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers

So how does the compiler look for classes you wish to import? Can it only see classes in the current directory (and sub-directories) OR those included in the classpath.

Could you tell me whats the difference between the classpath and PATH variables

Thanks for your help!!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So how does the compiler look for classes you wish to import? Can it only see classes in the current directory (and sub-directories) OR those included in the classpath.

Could you tell me whats the difference between the classpath and PATH variables



The compiler will find class files that are in directories and jar/zip files in the CLASSPATH. It will also find source files that are in the current directory, or subdirectories of it, if the directory hierarchy corresponds exactly to the package hierarchy.
The interpreter ("java") will find everything in the classpath, but not by default anything that is in the current directory or its subdirectories; for that to work you need to include "." in the classpath.

CLASSPATH is only used by Java. PATH on the other hand is used by the shell to find executable files (.exe, .bat, .sh, ...) I wouldn't advise to share any directories between the two, simply because they have such very different purposes.
[ July 25, 2005: Message edited by: Ulf Dittmer ]
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found some stuff on this so if anyone else has the same question:

The Path variable:

The PATH variable is a list of directories separated by semi-colons. These directories are where your system looks for commands when you try to execute them. If you don't add the location of the SDK tools to your PATH, you'll have to specify where they are every time you want to use them.

The classpath helps JDK locate Java software (class files) that are installed on your machine.


Cheers
 
Stephen Connery
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks Ulf Dittmer(and everyone else) for your response - I hadnt seen it before I posted - that helped to clear things up - cheers
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic