IntelliJ highlight everything as warning - java

After change env JAVA_HOME from Java11 to Java8, IntelliJ started to highlight almost every line of code in my project as warning.
In pom.xml I have java 1.8
In module settings I have also java 8
https://i.stack.imgur.com/D7WfA.png

When you encounter strange issues with the IDE there are a couple of things you can do to resolve the issue without removing and reimporting the project.
Using a Build System such as Gradle or Maven you can try to refresh the configuration by opening the "Gradle" or "Maven" view on the right hand side of IntelliJ and clicking Reload
In the top menu, select Build -> Rebuild Project
If all prior attempts fail, navigate to File -> Invalidate Caches and click Invalidate and Restart. It will force IntelliJ to re-index everything.
Those methods usually work.

Related

IntelliJ : Cannot resolve method 'run(java.lang.Class, String[])'

I've encountered a problem where on all of my applications, there's a red cross on the top right. I can run it, but the cross doesn't seem to go away.
I've opened the run/debug configurations and it says Warning : Main method not found. I don't understand why it's not found when I already have a corresponding main class and method for each and every application.
I tried to close the project, restarting IntelliJ, restarting my laptop, refreshing my desktop, refresh Gradle by clicking Reimport All Gradle Projects, rebuild the project and clicking Invalidate Caches / Restart. I also tried other suggestions I found on StackOverflow such as deleting the .idea folder. Nothing. The red cross still shows up. I've also realized that I do not have the out folder in all of my Applications.
I just set the language level to equal my SDK version at Project Structure. Finally, it is disappeared.
In Project Settings, First make sure SDK path is correct. Preferably install and use your own SDK. Then use the same SDK in Project and Modules in Project Settings.
File->Project structure ->SDKs
Choose JDK home path, if no jdk is in the path,
you'll see an icon download jdk
download then ok
Try to copy src and gradle folders and buil.gradle and settings,gradle files in separate folder. Then open this new folder as new project in intellij. Then intellij will propose Import as gradle project... - push it.
If problem remained see you build.gradle

Eclipse editor not showing error markers

My eclipse is not showing error in its file editor. I have tried cleaning and putting project on Build Automatically. However when I run it then I do see the compiler error in console and also in problem view just after saving the file. Does anyone have any idea how to fix this ?
This is the version of my eclipse:
Eclipse IDE for Java Developers Version: Neon.2 Release (4.6.2)
Adding more images:
Check the Build Path of the project by right clicking the project and select Build Path -> Configure Build Path.
JDK is not properly configure for project. Configure your JDK instead of in-build JRE.
Also make sure your source folder is also configure in Build Path (for example MyProject/src) must listed as a Source folder.
In Java Compiler-->Errors/warning, click Restore Default.
Make sure "Build Automatically" is checked.

Could not find or load main class in STS/Eclipse

I have a main method in a package in one of my projects. Say, the package is com.ant.car. I am trying to run and/or debug this main method, and I keep getting the error Could not find or load main class com.ant.car.
I've searched this problem, and it seems like I can't figure out what is wrong.
1) I've checked run configurations. In Run->Run Configurations, I've checked that the Main class is com.ant.car.
2) I've checked build path. If I right click on the project, I select Build->Build Path, and under the Libraries tab I make sure there are no missing folders with red Xs next to them.
Not really sure what else to do. Any suggestions?
Project -> Clean
this is working
Try updating project by right clicking on it. Maven -> Update Project
Today I ran into the same problem and I tried a lot of answers. Nothing helped. Cleaning the project, build automatically is already checked, deleting .metadata, etc.
Eventually I tried this and it worked perfectly:
menu Project -> Properties
Java Build Path, tab Libraries
Remove the JRE System Library from there, press Add Library, take the JRE System Library and press Next. Workspace default JRE and press Finish.
What worked for me:
Menu Project -> Properties
In Java Build Path, tab Libraries
Delete all libraries with a red [x] next to them.
In my case, problem happened when I switched from Kepler to STS IDE.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
Sometimes the problem can be caused by some newly added dependencies. Try removing the recently added jars. That's how I fixed my problem.
Project -> Clean... -> check project not working -> Clean
I already had build automatically set, but forcing STS to rebuild it fixed it.
This issue occurs when the main .class file moved or not found because you changed the directory for committed/shared the project into the git or another repository.
To Resolve this issue -->
Remove existing run configuration and new one.
Find the parent pom.xml or project pom.xml and open cmd/command prompt and run the below commands,
mvn clean install package
mvn eclipse eclipse
It worked for me:
1. Delete metadata from work-space directory.
2. Import the project again, but selected copy to work-space option.
I think the cause for the error was Non-English characters in the original saved directory.
You just need to delete Run Configuration file and restart STS and run command -mvn clean install and try to restart the service
The Error "Could not find or load main class com.ant.car" occur when your class is not in build path. please make sure that .class file is generated and it's in build path ..
I faced the same issue..
just do follow these steps:
STS/Eclipse --> Project --> Enable "Build Automatically"
then refresh your project, it will resolve your issue.
Still not refreshed your projects automatically, just restart your STS and check.
Hope it will help you.
I think .class files are deleted/missing from JavaProject/bin folder.
To resolve this issue ->
1) Just cut paste and save the code contents of all the files that you are using then .class files will be regenerated.
2) Then run the code and you can see it works fine if there is no syntactical errors.
1 ) Clean the Project
2 ) Enable build automatically Option
3 ) Update the maven project by use the short cut Alt + F5
Deleting target folder manually and mvn clean install worked for me
A quick and easy fix is to directly run your SpringBootApplication class (i.e. Right click, Run As -> Spring Boot App). This runs the app and creates a run configuration automatically.
I spent several hours on this issue, finally it is fixed by doing this:
Properties -> Java Compiler: uncheck the checkbox "use '--release' option"
This worked for me to solve the error. (I got this error after removing AWS ToolKit)
Close the Eclipse/ STS Eclipse.
Go to the WorkSpace folder.
Delete the .metadata folder.
Open the eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Remove project from STS/Eclipse
Close or Refresh the Eclipse/ STS Eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Tried above mentioned steps to resolved issue.
You can try one of the two solutions below:
Solution 1: Right click the project -> Gradle -> Refresh Gradle Project.
Solution 2: Add gradle or maven in your environment variable. My problem was that I had not added gradle in my environment variable. Before, make sure Gradle or maven is installed in your OS.
I tried all the answers but finally what worked for me was deleting the project from eclipse workspace and importing it again.

IntelliJ Bug: Scala 145, Error:scalac: Scala compiler JARs not found

I try to compile a simple object in IntelliJ:
object Test02 {
def main(args: Array[String]) {
println("Hello World");
}
}
I got this message:
Error:scalac: Scala compiler JARs not found (module 'scala02'):
E:\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.8.jar,
E:\.ivy2\cache\org.scala-lang\scala-compiler\jars\scala-compiler-2.11.8.jar,
E:\.ivy2\cache\org.scala-lang\scala-reflect\jars\scala-reflect-2.11.8.jar
I checked the Project Structure and checked the modules.
Modules are located here:
C:/Users/asus1/.ivy2/cache/org.scala-lang/scala-compiler/jars/scala-compiler-2.11.8.jar
How Can I change E: to C:/Users/asus1/ ?
Do I need to move all to E: ?
How people manage when the project and the jar are in different location ?
It seems a big bug of IntellJ ...?
Please goto File > Settings (Ctrl+Alt+S, Windows)/Preferences (Mac) > Plugin
Search for "scala". Uninstall Scala plugin.. Restart IDE.
Reinstall it. Restart IDE and install the plugin. Everything works OK
In the more recent versions of IntelliJ (2020.1.1) at the time of writing this, I was able to solve this problem by removing the Scala SDK configured in the Global Libraries section in IntelliJ and hitting File > Invalid Caches / Restart.
I'm not sure why this solved the issue, perhaps recent versions of the IDE now have automatic detection of Scala compiler JAR files from Maven (which I'm using to build my project).
If your project is Gradle-based, one possibility is that the project is looking for Scala libraries in the .m2 cache that don't exist. To confirm, open "Project Structure...", go to "Libraries", and examine the list for "Gradle: org.scala-lang:..." that contain errors related to missing files.
If this is the issue, simply re-import the project from scratch.
SOLVED as Follow:
In project settings, you need to manually add:
JDK Folder
Module and dependencies to JDK AND Scala JAR
In library, Add MANUALLY the JAR of Scala (IntelliJ does not add those JAR. it creates compile issues).
in Global library, check the JAR of scala are same.
There is an option to see the DEBUG in verbose mode:
https://intellij-support.jetbrains.com/hc/articles/207241085
This is very useful.
https://www.jetbrains.com/help/idea/invalidate-caches.html
IntelliJ IDEA caches a great number of files, therefore the system cache may become overloaded. Sometimes the caches will never be needed again, for example, if you work with frequent short-term projects.
When you invalidate the cache, IntelliJ IDEA rebuilds all projects ever run in the current version of the IDE.
Clear the system cache
1.From the main menu, select File | Invalidate Caches / Restart.
2.In the Invalidate Caches dialog, select an action. You can invalidate the caches and restart the IDE or just restart the IDE.
This worked for me.
Open File -> Project Structure
Go to Libraries under Project Settings
Click on the minus button on the erroring Scala library
Open an existing Scala class in IntelliJ and you will see the prompt to set up Scala SDK and click on that
For me, the following solution worked:
Go to Project Settings > Modules > Dependencies, select the Scala SDK, Edit, and correct the path of the Scala JARs:
Update #Oct 2021: This error means plugin needed an update and was solved by : goto File > Settings (Ctrl+Alt+S, Windows)/Preferences (Mac) > Plugin Search for "scala". Update.
This could be the issue :
You may have multiple maven projects linked/imported in single IntelliJ IDE window
and those maven projects are using different Scala compiler versions.
First you will get multiple compiler versions detected issue, then to fix this issue
if may have deleted some compiler version folder/jars from .m2 repo.
Solution : Go to maven view/tab --> Unlink maven projects from IntelliJ IDE which are using different versions of Scala , keep only projects which are using same version of Scala
In IntelliJ, ensure that the external libraries are present.
If already present, open library settings and check the path to the jars is not in red.
If in red, correct the path to the jars

Maven 2 project error icon in Eclipse

I have create multi-module maven project in Eclipse IDE (already installed M2Eclipse plugin). There I can build my project successfully. But after build also it shows errors icon in my every module project. What kind of issue it can be?
Thank You.
Without knowing what errors you are seeing I am going to assume that your issue is with eclipse project properties (build path, src directory specification, output classes directory, etc).
You tagged m2eclipse plugin, so you should be able to right click on your project in eclipse select maven->update project configuration. If you do not see that option under maven then you should first see an option called maven->enable dependency management. Click that first and then you should be able to see update project configuration option.
If this does not fix it, then open your project directory containing the pom.xml file in command prompt and run mvn eclipse:eclipse.
One of the above should resolve those pesky error messages provided that your maven build itself is successful.
In eclipse open the Markers Tab (You can open it from Window -> Show View -> searching Markers)
It will show all the related errors with your project. You can identify your problems related to your problem, and solve accordingly. Sometimes it shows Quick Fix option, which is helpful.
For me, the above solution listed out by #CoolBeans was not working out, so i searched further and found out the following:
Go to Problems windows(present besides of Console window). If it is not there then click on Window-> Show View -> Problems
Inside Problems you will be able to see the Errors Description related to your project. In my case it was "java compiler level does not match the version of the installed java project facet". If that is the case for you as well, just follow below steps:
Right Click Project -> Properties
Click Project Facets(present in the left hand side list)
Choose the correct java version in Java Project Facet
Click Apply
That's it!

Categories