When I try to use ctrl+space
this error is shown:
This compilation unit is not on the build path of a Java project.
I see tha
If it is a Maven project then sometimes re-importing of it helps:
Hope it will resolve the issue.
In my case, I have Eclipse Maven project. I had the same issue and I posted detailed explanation of the issue and answer here Eclipse Maven - Code Completion fails "This compilation unit is not on the build path of a Java project" and "Failed to Download Index" Error
If your project is imported as an existing maven project then --> Just right click on project and do maven update. It resolved my similar issue.
Another alternative to Loganathan Mohanraj's solution (which effectively does the same, but from the GUI):
Since you imported the project as a General Project, it does not have the java nature and that is the problem.
Add the below lines in the .project file of your workspace and refresh.
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Go to Project-> right Click-> Select Properties -> project Facets -> modify the java version for your JDK version you are using.