I have several Android projects in Eclipse, and all is fine, except one (a library) that can not resolve any imports.
The java.io imports do resolve fine in other Android projects in the same workspace, and previously (I haven't used it for over a year) this library worked fine, too.
Any ideas?
Check two things
Eclipse preferences
Check your Eclipse preferences: Java -> Installed JREs
The one that you're using should be marked and it should be a JDK not just a JRE.
Project build path
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the libraries folder whether the JRE System Library is present and ...
If not add it using Add library -> JRE System Library and then
select the correct one (from an installed JDK).
I am using Maven an this is what I did to re-solve -->
Right click on project
Maven -> Update Project. Make sure you choose 'Force update of Snapshots/Releases'.
Also check the 'clean project', 'update project conf from pom' and 'refresh workspace resource options' and click ok.
The following worked for me:
Close the project and reopen it.
OR
Clean the project ( = rebuilds the buildpath and thereby reconfigures the JDK libraries).
I was missing the JRE Systems Library in my Project Tree.
And navigating to Projects' Build Path and 'Add(ing) Library' worked!
I just ran into this problem with Eclipse 2022-6 and java-17-openjdk-amd64. I just appeared during editing in another file, the same code had worked before.
For me, all settings were correct and none of the above tricks worked. What I then did was completely removing the import command import java.io.Closeable;, saving the file, adding the same import command back at the same place, and saving again. The error disappeared.
Related
I just installed Eclipse Oxygen and tried to open an existing project into the workbench but I get this error:
The project was not built since its build path is incomplete. Cannot
find the class file for java.lang.Object. Fix the build path then try
building this project
I tried right clicking on the project - went to Properties - Java Build Path - Libraries - Add Library - JRE System Library and selected Workbench default JRE (jre1.8.0_60).
I then cleaned and rebuilt the project but it then causes more errors to come up like:
ActionBar cannot be resolved to a type
Activity cannot be resolved to a variable
AdapterView cannot be resolved to a type
ArrayAdapter cannot be resolved to a type
Here is what made the error disappear for me:
Close eclipse, open up a terminal window and run:
$ mvn clean eclipse:clean eclipse:eclipse
Are you using Maven? If so,
Right-click on the project, Build Path and go to Configure Build Path
Click the libraries tab. If Maven dependencies are not in the list, you need to add it.
Close the dialog.
To add it:
Right-click on the project, Maven → Disable Maven Nature
Right-click on the project, Configure → Convert to Maven Project.
And then clean
Edit 1:
If that doesn't resolve the issue try right-clicking on your project and select properties. Select Java Build Path → Library tab. Look for a JVM. If it's not there, click to add Library and add the default JVM. If VM is there, click edit and select the default JVM. Hopefully, that works.
Edit 2:
You can also try going into the folder where you have all your projects and delete the .metadata for eclipse (be aware that you'll have to re-import all the projects afterwards! Also all the environment settings you've set would also have to be redone). After it was deleted just import the project again, and hopefully, it works.
In Eclipse, Right click Project -> Maven -> Update Project. It fixed errors in my project.
I'm also using Eclipse Oxygen, migrated from Mars. I faced the same error. I deleted .metadata, .recommenders folders and added projects from archive and issue is solved. I also use Android Studio but i like Eclipse much more.
At my system the Java Runtime JAR file jrt-fs.jar was not found because it was in the wrong directory. This file should be located in the "lib" subfolder. If you installed Java at "C:\Temp\java" the file should be here at C:\Temp\java\lib\jrt-fs.jar .
These are the steps to make jrt-fs.jar available to Eclipse:
Window / Preferences -> the "Preferences" Window opens
Select in the left menu: Java / Installed JREs
Press the [Add...] Button -> A window opens
Select "Standard VM" - The window "JRE Definition" opens.
Enter your path information:
JRE home = "C:\Temp\java"
JRE name = "MyJRE"
Select [Add External JARs...] to link the jrt-fs.jar
JRE system libaries: "C:\Temp\java\lib\jrt-fs.jar"
It worked for me with OpenJDK12 and Eclipse 2019-09 (4.13.0).
Eclipse reported me this error:
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
I had faced this problem. I added the C:\Users\Office 2\android-sdks\platforms\android-19\android.jar to the Java Build Path's Library. And the project started to run again.
The problem occurred due to my carelessness. Yesterday night I was updating the Android SDK, and at the same time I tried to run the project, while the SDK Manager was uncompressing the system image. The Project couldn't start and the error occurred.
I tried all the methods given by others. But nothing worked. It solved when I added the android.jar to the library.
I guessed it that android library is missing. not the Java, when I saw the errors only at the android methods and imports. But when I read the posts, I got confused and wasted some time trying wrong way.
I had faced the same issue and tried different solutions, I have reinstalled my JDK 11 and restarted the machine, after that the issue gets resolved.
I got this out of the blue in a workspace that was working properly before. This problem seems to indicate that the project configuration somehow got corrupted.
Restarting Eclipse didn't help, but in the same vein as the answers dealing with Maven, regenerating the Eclipse project config with:
./gradle eclipse
or
./gradlew eclipse
if you use the wrapper, solved this problem for me.
I have similar issue when importing Spring Boot, jdk 11 (using
inside docker) project to Eclipse 2019 (2021), in Ubuntu, instead when
importing to Inteelij IDEA Community or NetBeans IDEs they do
not produce the same set of after-import errors as in Eclipse.
The Spring Boot is multimodule maven projects and two child
modules give such 2 "problems" in appropriate problems tab:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.Object. Fix the build
path then try building this project
Next 2 errors are produced in two classes of aforementioned
maven modules:
The type java.lang.Object cannot be resolved. It is
indirectly referenced from required .class files
Manipulation with adding JDK 11 to submodules buildpath
just leads to the thousands of problems. Also it is
got when I use Eclipse-File-Maven-Update.
Moreover when I try to edit most of existing classes or add new ones
I got red underline that tells
Implicit super constructor Object() is undefined for default
constructor. Must define an explicit constructor
. So almost no opportunity to use Eclipse
even at prebuild stage as docker-compose should run build and
run. Indeed I noted that such issue is produced just when project
also uses modules (module-info files introduced in java9).
When I import project on jdk 8 (even not installed on
system), or even on jdk11 without module-info files all
is fine in Eclipse after import.
Another difference is that of when I use problem old no module
project the Build Path is composed with jre environment 8 and
maven dependency items, but when using
"module-info" project the Build path contains -module path,
and -classpath. So I even do not know where to add jre 11,
indeed adding does not resolve issue, just make more errors.
So what is the resolution of the case??? What settings to do
in 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.
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
I'm making a webapp in Eclipse. I use to make it in my Desktop. And today I got a laptop and I've copied the workspace in my Desktop to laptop.
And after copying the workspace, I've opened my Eclipse pointing to the copied workspace. And when I opened my Java files, almost every line is red underlined .
In my desktop there was no problem with this app, It used to work fine.
When I started my Eclipse with this copied path, I though the errors were due to the jar files (I used to have jars in my desktop associated to this project).
Even after configuring my Build path, the red lines still appear.
How can I solve this?
A wild guess: The path to the JRE is wrong so the compiler does not find the Java standard library. When none of the standard library classes are found you get compile errors at almost every line.
Solution:
Configure the path to the JRE in the compiler settings:
Preferences → Java → Installed JREs
And/or configure the path to the standard library in the project settings:
Project settings → Java Build Path → Libraries
Edit existing entry for system library or add a new one.
You don't want to just copy the workspace over. You want to import the project into Eclipse. You will also want to make sure that you import, and add, any external .jar files. To import use:
File > Import > Existing Project into Workspace
Did you use the import wizard after setting your workspace (http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-importproject.htm)? This is the important part. Once that's done be sure to do a clean build. If you see errors then, you might still be missing external jars that you had on your desktop.
When I installed the latest installment in Mac OSX - the Mountain Lion - I experienced some problems getting Eclipse to work I also lost most of my Android developer files (but I still have my projects). I suspect this is due to the choice of removing the /Developer and move the XCode and other Apple developer tools (I placed my Android tools here).
I have now installed the latest version of Eclipse and the problem still seems to be around. There are errors in all my projects and I get an error message prompting:
The type java.lang.Object cannot be resolved. It is indirectly referenced
from required .class files
I tried to check the Java class-path both in Eclipse and in my terminal and these seems to be OK. java and javac both run in my terminal and there is a valid path to the java source files in Eclipse (Under Preferences, Java, Installed JREs). That being said I'm not an expert in Eclipse so there may be that I have misunderstood how this problem ought to be solved. Anyone here with similar problems or who know the cure?
Make sure that you have a valid JRE or JDK defined in the Java Build Path of your project. Right-click on your project, select Properties... and then Java Build Path.
I had this problem moving a Maven project from Eclipse to RAD. I had a JSP file that worked in Tomcat and JBoss, but threw a NullPointerException in WebSphere on the form definition during the compile.
Anyway, after transforming the Maven project into an Ant project (mvn ant:ant), I imported the Ant project into RAD and got this error. The fix:
Open the Java Build Path, selecting the Libraries tab.
Find the JRE System Library and remove it.
Add the JRE System Library.
Goofy, but it works. It must reset some property in a file. I don't know if the problem is the older version of Eclipse or RAD.
After updating my Android SDK to make Appcelerator Titanium happy, I started getting "java.lang.Object cannot be resolved" for my Android projects in (non-Titanium) Eclipse.
I updated all dependencies in Eclipse, and the error healed after a restart of Eclipse.
I had that error almost every time I launched Eclipse for the first time; if I close and then re-open Eclipse, the error is gone.
I found this solution useful, though (I've copied here to protect the link, credit goes to the original author):
In Eclipse go to Windows -> Preferences -> Java -> Installed JREs.
Select the currently active JRE/JDK and press the Edit button.
Select the rt.jar and change its position in the list of JRE system libraries (e.g. press the Up button once).
Confirm all changes, clean and rebuild the workspace.
The next time you face the problem reposition the rt.jar again (or reset the order by pressing the Restore Default button).
please select your installed system jre version from java build path.
Try the following and problem will go away
Close the project and reopen it.
Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
OR
Delete and Re-import the project and if necessary do the above steps again.
This is an annoying Eclipse Bug which seems to bite now and then. See http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html for a possible solution, otherwise try the following;
Close the project and reopen it.
Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
OR
Delete and Re-import the project and if necessary do the above steps again.
The better cure is to try NetBeans instead of Eclipse
I got this error and what I had to do was remove the JRE from the Window/Preferences/Java/Installed JREs and re-add it. This somehow cleared up eclipse's cache and rebuilt the project successfully. To get rid of the error in the file-editor I also had to close it and open the file once again.
My problem was that I had in Eclipse: Window / Preferences... and then in the tree on the left Java / Installed JREs: C:\Program Files\Java\jre7
I changed to: c:\Program Files (x86)\Java\jre7
It solved my problem.
I had the same issue and none of the above solutions worked for me.
Then I realized than the library (libs) folder was missing in the project. Once i added the libs folder and the corresponding Jar file, the issue was resolved..
If your project specific (or if not applicable, workspace default) JDK/JRE is being referenced correctly and you've just begun to get this issue out of the blue: restart Eclipse.
Unfortunately, "restart Eclipse" is one of the standard troubleshooting steps when a project won't build. Eclipse even has a dedicated entry under the File menu.
I had to add the JDK under the build path. After adding the correct build path it worked.
I just had to restart eclipse, and the error went away. Strange.
I solved this by pointing my eclipse to the jre available in jdk.
This error caused by invalid sdk is pointing in your project.properties file of your project.
project.properties -> target=android-19 . change to version which is installed in your eclipse.The error will be gone.
I had the same issue after moving from JRE7 to JDK7. Finally I had to remove the JRE7 configuration from the Eclipse preferences and then add the following two lines to the eclipse.ini file.
-vm
C:\Program Files\Java\jdk1.7.0_55\bin\javaw.exe
I had this problem, and I understood that Eclipse has automatically imported a core reference, instead of the reference for the project I needed.
Deleted the import, and rearranged it, and everything worked fine.
Same problem facing Me
Project->properties->Android
And select the api level and also go in java build path and check some external jar file path if we already add in it.update the jar file path
On "The type java.lang.Object cannot be resolved. It is indirectly referenced
from required .class files":
I found my project had 2 meta-inf.java files in 2 different directories with the same 'module ' on line one (a copy/paste error).
Once this was corrected, I cleared the meta-inf.java file with the issue, rebuilding it line by line, guided by Eclipse, until I had a working module configuration.