cannot access the classes in the package
Mia Lopez
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
7 Answers
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.
2There 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.
I recently had this issue and it was because I had a class file in the same directory as the java file that I was compiling. You need to delete all .class files in that directory.
Well I guess I am literally 8 years late, but today I had this problem and I managed to solve it just re-writing the state of the class. Seems that if you comitted your project, pulling it back could make you have that problem, but writing again the "public" state of your class worked for me. I Hope it works for you guys. chrss.
I deleted the out folder and the problem was solved
For me it happened after updating java to jdk_16.
it was solved after I changed the "misc.xml" file inside ".idea" folder. changed languageLevel="JDK_15" to languageLevel="JDK_16".
In Intellij, try
- Go to File
- Invalidate Caches/Restart
- You can choose only Invalidate and restart