I Have DataLayer and logicLayer as packages in my project. I want to delete the default package since I do not need it. But When I delete I got the following error.
Error: Could not find or load main class
How can I slove this problem?
Move your main class from the default package to any other package and then a simple refresh would solve the problem.
The problem is that the default packeg is contains a class which is empty but cause problem.As soon as I delete that class the package is delete automatically.
Related
I've just started a new IntelliJ project. When I try and import a java class with the IntelliJ import shortcut, the import is being added to the object and not to the top of the class like it normally would.
Where in the settings can I change this?
See Preferences/Settings > Editor > Code Style > Java if this option ...
Use fully qualified class names
... is ticked then IntelliJ will always use fully qualified class names. If you disable this option then Intellij will include the import statement and refer to the class by its 'simple' name.
Here's a screenshot showing this configuration item:
If the accepted answer is not working for anyone, Try the below points too.
Check whether the class file is in correct package and resolve if there is any issues in the class file.
Click File -> Invalidate Caches/ Restart and Click Invalidate and Restart button, Once it restarted U'll be able to import properly.
I was facing this issue with my custom / generated(protobuf) java packages.
Solution (TDLR)
Whenever you face this issue, just check the package or class that getting imported doesn't have any error(red marking).
If so try to fix that.
I was having an issue with package naming and its actual location. By generated-sources -> Right Click -> Mark Directory As -> Sources Root corrected my issue.
Check whether generated-sources or folder under the generated sources need to mark us Sources Root.
My issue was with generated java files (Adding this just to help someone else with same issue)
Intellij shows red mark for Import with wildchar(import pkg1.subpkg1.*;). Like editor was unable to recognizing 'import all' under a package.
But direct import to the inner package was fine.
On top of that an resolving issue with import class add full package to the Class itself, instead of adding import statement on top the java file.
This issue didn't affect the code compilation, only in editor it was showing red mark.
Here is my directory structure within the "java" folder,
The problem is in my MainActivity file when I write.
import api.gitapi;
import model.gitmodel;
I get a warning message saying "Unused Import"
In my MainActivity file, I get an error on line,
gitapi git = restAdapter.create(gitapi.class);
and,
public void success(gitmodel gitmodel, Response response) {}
saying that the symbol gitapi and gitmodel cannot be resolved. I have tried "Invalidate caches/restart" but the problem still exists.
Any help is appreciated, thanks in advance!
PS: If it helps, I'm using this tutorial
You have placed the gitapi and gitmodel classes into a test source folder, meaning that they are available to be imported by other classes in the test folder, but not in the main folder (where your activity lives). Create those classes in the main source folder and your activity will be able to import and reference them.
just need to refract the classes into the package containing MainActivity.class and it might solve your problem and you will get the result what you want.
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
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.
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.
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
See this answer
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.
Someone help me please? I don't know why can't I run a simple program by the run configuration. If I don't set a package in the beginning it works.
I attach a picture of my screen
The class bb is in the package aa2. Its name is thus aa2.bb, not bb.
If not specified the package name externally then a given class is said to be included in default package i.e this class exists directly under src folder.
If you remove the package statement in the class then you have to move this class to one folder level up, in order to run this class.
But it is discouraged and normally it is expected that each class should declare its own package statement.
The screenshot is the error I am receiving. I am trying to use the class ConnectDB contained within the package CIS4362Connect1, in the class AdminManager in the package myconnectoracle. Why can't I import this class?
As comments above indicate, it is possible that your ConnectDB is not public, in order to use that close outside of the its package, it must be declared public
Please refer to: Access control documentation
EDITED: (Solution)
The problem is that packages are case sensitive, you have a different case in both packages declaration.
inside the ConnectDB class you maybe have cis in lower case.
As far as I can tell, the class you are looking for is not defined in the current project. Try referencing the project with the package you are looking for in the libraries, or just move the package/class.
I just got a very similar issue with one of my class being unexplicably unimportable. I tried building the project anyways, and it did build successfuly, despite errors showing everywhere.
Moving the package to another location within my ide, and then moving it back to where it was supposed to be located somehow solved the issue for me.