Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

cannot access the classes in the package

Writer 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

9

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.

2

There are two possible reasons why this happens

  1. 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.

  2. Are your classes public? If you forget the public modifier, classes will have package visibility and cannot be accessed from other packages.

  3. Oh well, nobody expects the spanish inquisition ... check your spelling carefully, including capitals.

2

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

  1. Go to File
  2. Invalidate Caches/Restart
  3. You can choose only Invalidate and restart

See this answer

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.