| Author |
A problem with package visiblitly
|
Femi Alla
Ranch Hand
Joined: Jul 05, 2002
Posts: 79
|
|
Hello everyone. This question ended up being so long. But there's no way else I could have put forward the question. In my daily programming practice, I was trying to create a kind of multithreaded application..... Put it in a folder/directory which has two subdirectories in which there are other applications which both display the output of a counter. And in the parent directory, I put the main application which activates the other two. This had worked perfectly well with all of them in the same folder. This was when I ran into problems. It just didn't work...in different folders that is. The parent folder is called TheMultithreadedExperiment, and the other folders it contains are "Folder1" and "Folder2". The main one that calls the others is MainThread.java and the others are InFolder1.java (which is in Folder1) and InFolder2.java (in Folder2). The codes are below. The compiler messages are below the programs. Please do take a look. Please meet MainThread.java /** Here, I was trying to put threaded programs in the diferrent folders and let one main program active the others, and display what is going on in the different folders. this is the one in Folder1 This is the one in Folder2. The files reside in C:\JavaPrograms\PersonalPractice\PersonalExperiments\TheMultithreadedExperiment The error messages I got for the version of this programs pasted up here was: C:\JavaPrograms\PersonalPractice\PersonalExperiments\TheMultithreadedExperiment> javac MainThread.java MainThread.java:9: cannot access InFolder1.InFolder1 bad class file: .\InFolder1\InFolder1.class class file contains wrong class: JavaPrograms.PersonalPractice.PersonalExperimen ts.TheMultithreadedExperiment.InFolder1.InFolder1 Please remove or make sure it appears in the correct subdirectory of the classpa th. import InFolder1.InFolder1; ^ 1 error This was even after I had used the command set classpath = C:\JavaPrograms\PersonalPractice\PersonalExperiments\TheMultithreadedExperiment Before this, I had even made the import statement look like this in the two child programs: import JavaPrograms.PersonalPractice.PersonalExperiments.TheMultithreadedExperiment and then the error messages were better, I guess. It was something along the lines of "package JavaPrograms.PersonalPractice.PersonalExperiments.TheMultithreadedExperiments.InFolder1 does not exist." But I decided to change this 'cos I reasoned that the dots (.) in an import statement is meant to separate subclasses (or is it packages?). I really need help here. Can any one figure out what's wrong? (edited by Cindy to format code) [ July 24, 2002: Message edited by: Cindy Glass ]
|
SCJP
|
 |
Snigdha Solanki
Ranch Hand
Joined: Sep 07, 2000
Posts: 128
|
|
The import statements are wrong. It should be import InFolder1.InFolder1; import InFolder2.InFolder2; Although InFolder1.java is in directory Folder1 but the package statement does not include that.If you say package InFolder1; then the class file will be created in a directory InFolder1. javac -d . InFolder1.java will create a directory InFolder1 and put InFolder1.class file in it. Hope this helps.
|
Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
|
 |
Jessica Sant
Sheriff
Joined: Oct 17, 2001
Posts: 4313
|
|
also, the classes InPackage1.java and InPackage2.java need to be declared public -- otherwise they won't be accessible by MainThread.java. Once you fix the above errors, you'll get a few more compile-time errors due to typos in MainThread.java -- but you should be able to fix those by the descriptive error messages. Lastly -- check out the handy dandy UBB [CODE] tags -- they help preserve whitespace and improve code readability.
|
 |
Femi Alla
Ranch Hand
Joined: Jul 05, 2002
Posts: 79
|
|
|
Thanks a lot. It worked.
|
 |
 |
|
|
subject: A problem with package visiblitly
|
|
|