Hello, I've been cruising along nicely until I tried creating my first package. I'm working out of chapter 5 in Thinking in Java and I'm having the following problem. First, the preliminaries... I'm working on Windows 95 using JDK 1.3. My CLASSPATH is: SET CLASSPATH=.;C:\jdk1.3\bin;C:\javaprog;C:\javaprog\javaranchcommon.zip; In my javaprog directory I have the following file:
In the c:\javaprog\mypackage folder I have the following file
MyClass.java compiles fine, but I get the following error when I compile PackTest.java: [Windows 95] C:\javaprog>javac PackTest.java PackTest.java:6: cannot access MyClass bad class file: .\MyClass.class class file contains wrong class: mypackage.MyClass Please remove or make sure it appears in the correct subdirectory of the classpa th. new MyClass() ; ^ 1 error I have things setup the same way on a Win 2K system and it works fine, but I'm at a loss as to why it doesn't work on my home Win 95 system. I have a suspicion that the solution to this is staring me in the face, but I'm not seeing it. I would appreciate any insight anyone here could offer. Thanks in advance, Pat B.
Well im no expert on 95 or anything, since all i use is 2k. But i think this may have something to do with your prob. SET CLASSPATH=.;C:\jdk1.3\bin;C:\javaprog;C:\javaprog\javaranchcommon.zip; Ok, so thats your path. But later on you say that your package is in c:\javaprog\mypackage. Now im not sure on this, but shouldnt you include the /mypackage directory in your classpath?
Joined: Jan 03, 2001
Thanks for the reply Andy, Your answer wasn't the right one, but it got me to realize what the problem actually was. Before I got to the part in the TIJ book about saving all your package files in their own directory I had originally saved and compiled myClass in the javaprog directory. Later, I added the mypackage directory and rather than moving the file I copied it, leaving a different version of myClass in the javaprog directory. Since the CLASSPATH just provides a starting point for the compiler to look for the necessary packages it was hitting my original myClass, which was the cause of the error. I hate to admit such a mindless error, but hopefully this will help someone else down the road. Thanks again, Pat B.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com