Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A problem with package visiblitly

 
Femi Alla
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Snigdha Solanki
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic