I have the following directory structure :
MessManagement is the parent directory.
Under that i have 3 directories :
student , messconvener,messmanager
The student directory contains the Student.java and Student.class files. The messconvener contains the MessConvener.java this requires the Student class as MessConvener is extended from Student itself.
How should i do the packaging of the classes....??
What i have tried so far.
Code :
This is Student.java
package MessManagement;
import java.sql.*;
public class Student
{
}
This is MessConvener.java
package MessManagement;
import MessManagement.student.Student;
public class MessConvener extends Student
{
}
But this does not seem to work.Error Meesage :
MessConvener.java:2: error: package MessManagement.student does not exist
import MessManagement.student.Student;
^
MessConvener.java:3: error: cannot find symbol
public class MessConvener extends Student
^
symbol: class Student
2 errors
No one can access classes outside of the package, except for your own classes, which are implemented in the package. 6. What does ‘public’ access type mean for a class implemented in a package? The class in the package can be publicly available for use in other external libraries.
The word ‘class’ is preceded by the ‘public’ access modifier. The class is accessed using the package name and the name of this class, separated by the symbol ‘ . ‘; the ‘package’ access level.
The issue can be summarized as attaching the jar file source fin 'B' module to a dependency causes the "cannot find classes in same package issue" in the module 'A' whose source is referenced. 2. Open module B dependencies dialog, attach sources to module A source dir Select Build -> Rebuild Project, it works for me!
In the module, a ClassB2 class object is correctly created, because the ClassB1 and ClassB2 classes are in the same PackageB package, which is accessed by default. An attempt to create a ClassA1 class object is failed, because the ClassA1 class is declared in another package and there is no public access modifier for it.
The error you're getting makes sense. The Student class is located in MessManagement package not MessManagement.student package.
So either remove your import of Student in MessManagement or change the package name in Student to MessManagement.student.
For me, I got this error for a different reason and this was in a maven project. It began to occur after I made major changes to the classes and copied in a lot of new classes. There were no conflicting package names as in your case.
The solution was to do mvn clean.
After this, I didn't get that error anymore.
There are two possible reasons why this happens
Is the root of your directories included in the classpath? You need to specify when starting a java program. See the documentation on how to do that or this variant for unix.
Are your classes public? If you forget the public modifier, classes will have package visibility and cannot be accessed from other packages.
Oh well, nobody expects the spanish inquisition ... check your spelling carefully, including capitals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With