No syntax highlighting in eclipse for java - java

There is no syntax highlighting in java files in my eclipse..This happened all of a sudden..Not sure why..
This is how it is looking now..
As mentioned in other posts..i tried to change the color from preferences window and there is nothing when i type java..something really messed up...
AAny suggestions..
Update:
It seems Java plugin is not installed..as per the below screeenshot
And when i try to install java plugin it says new version is already installed as per the below screenshot

Closing the file's tab and re-opening it fixed it for me.
(I actually closed all the tabs...)

I faced the same issue all of a sudden after a commit/update project operation.
The point is, default editor of Eclipse has changed somehow and we have to set it back to normal.
Try the below method,
1. Goto Windows -> Click Preferences
2. From the Preferences window goto General -> Editors -> Click File Associations
3. You can choose the default editor for *.java files here
When I first opened Preferences, 'Text editor' was set as the default editor for .java files and then I changed it back to 'Java Editor'.
Now it works perfectly fine.

You probably have a corrupt installation or you have recently installed a corrupt plugin.
The following steps might help.
In your Install window,
view your "already installed" plugins.
select the "Installation History" tab.
select a previous stable configuration
Click the "Revert" button

TLDR; open another workspace, then come back to the original workspace.
Ok this is odd, but for me, all the highlighting suddenly went away for Java files. I explored all of these ideas here, with no effect. I created a new workspace, planning to move everything to it. I realized that can be a pain to move many projects over, so I went back into the original workspace to look at some settings, and poof - the highlighting was working again.

I have one java class file like a text editor.
I tried following,
Select the respective java class file from eclipse.
Right click on the file and mouse hover on "Open with".
Select java editor.
Now its works.

Related

Eclipse - Ctrl+Space Content Assist doesn't work

I have just installed the 2020-12 version of Eclipse IDE, and I simply cannot get the Ctrl+Space suggestions to work. Every time I try to use them I get an empty suggestion box.
I've already searched for this of course, and I've found many who suggest how to fix it.
https://superuser.com/questions/209752/eclipse-doesnt-autocomplete-and-find-references-anymore
Eclipse - CTRL+Space autocompletion does not work any more for Java
https://mkyong.com/java/content-assist-ctrl-space-is-not-working-eclipse/
No Default Proposals in Eclipse Juno
Eclipse/Java code completion not working
Most of these say I need the Other Java Proposals in the settings, but if you look at the image you see that that option doesn't even exist! In the image the default settings are applied but I've also tried to check every single one of those boxes and still get an empty suggestion box when I press Ctrl+Space at the end of Combi (also in the image).
Image of the issue and my settings: https://imgur.com/a/CVRRgC0

IntelliJ Not Highlighing Anything

When I create a new Java project or open an existing one, IntelliJ doesn’t highlight any of the text nor does it suggest anything. All the code is 1 single color. I’ve marked my src file, made sure power safe is off, made sure highlight is enabled, and even reinstalled IntelliJ CE. I’ve also disabled all plugins. Any suggestions is appreciated.
picture here
Your screenshot shows that the file is not recognized as a java source file.
Go to Preferences -> Editor -> File types
Scroll down in the list of Recognized File Types and click Java.
In the list of registered patterns make sure it shows *.java.
Also ensure the file is not marked in the Ignore files and folders section at the bottom of this preferences panel. Perhaps you added it by accident (with some shortcut).
Also, while reinstalling IntelliJ, you have probably imported your previous settings. With it, you inherited this issue.
If this doesn't help, please share a screenshot of your project/module structure and setup.
Last but not least, try to create the file using the context menu. E.g. try to right click on your src folder and select new and select Java class or Package from the options. Would be good to check anyway, to see if these are valid options. If they do not appear here, it indicates the project setup is erroneous.
Solved! Thanks to #yole I did the following 'make sure that the *.java extension is listed in "Registered patterns" for the Java file type in Settings | Editor | File Types".

Eclipse for Java not loading in packages and classes

so I'm relatively new to Eclipse and programming in general, started using Eclipse for Java a few days ago. It all went well until today. When I open Eclipse, select path, etc. there are no errors or anything but all my classes and packages that are supposed to show on the left side are gone, and it's not the bar that's gone - it's still there, it's just blank. By now I've done some googling but I still have no clue how to fix it. Sure, dragging every file into Eclipse one by one works but even after that, the package explorer bar is still empty as my tea cup right now..
You can try the below setting to get the packages/classes back again:
Window->Reset Perspective
I think you are accessing wrong workspace.. Switch to correct path.
In eclipse,
File. -> Switch Workspace -> Other -> select dropdown too see any other workspace available..
Select correct workspace and check whether the packages and classes are available..

Eclipse Luna - Project is not showing up - Strange

I just installed Luna. I imported 3 projects all went well for a while.
Then I restarted eclipse and now it shows only two projects. I tried to import the missing project, but it says it already exists in the workspace.
I closed all other projects and pressed Ctrl+Shift+T to see if it still shows up the types from that invisible project. Yes, it shows files from that invisible project. I opened one of the files and selected Show In Project Explorer. Nothing happens.
Also, in the code when I press . after an String object, nothing shows up.
Seems to be strange. Any help?
Also, if I can do fresh import of all projects, that would help too. But again, I don't know why context assist is not working. I can try importing everything afresh. For this, what are all the eclipse related folders / files I need to remove?
Edit
this helped me with workingset / missing projects. But when I press . after an object, nothing comes up.
For others benefit, it has to do with Working sets. You can click Down arrow in Project Explorer and select "Edit Active Working Set". In the window, on the left hand side, you can see your non-visible projects and move it to right hand side to make them show up under active working set. HTH.
Regarding the problem where Eclipse says it "already exists in the workspace": I recently had a similar problem and I fixed it by unchecking the box that says "copy projects into workspace" and then hit refresh and it should work.
Just fixed this issue by clicking 'Deselect working set' ( under dropdown in project explorer ). For me, 'edit Active working set' was disabled to start with.
It sounds like the projects exists on the file system in the workspace directory, but the actual project got deleted or never imported in the eclipse workspace. Take a look at the workspace directory, all three projects should be there. You can delete the "missing" project from the file system and reimport it again.

No completions available, strange Eclipse behavior

I think I tried every suggested solution, but this Eclipse auto-complete problem is quite particular:
I launch Eclipse, content assist works fine;
I want to create a LineBorder in my Swing project;
I type LineBorder panelBorder = new Li and hit Ctrl+Space;
No popup appears and in the status bar it writes in red "No completion available";
I try Ctrl+Space on the elements where content assist worked fine 2 secs earlier, it doesn't work anymore.
I try the same thing on other project, on the same project after closing and reopening it, after cleaning it and content assist works just fine before I try using LineBorder constructor, then it crashes.
What I tried:
Reset to defaults in 'Preferences->Java->Editor->Content Assist->Advanced';
Check every single checkbox in the same menu;
Create a new workspace and try it there;
Delete .index files and 'savedIndexNames.txt' in .metadata/.plugins/org.eclipse.jdt.core;
Check for the duplicate libraries.
What I didn't try is reinstalling Eclipse. The version I use is Eclipse IDE for Java Developers (Juno).
Nothing seems to work.
UPDATE:
Checked the logs as iGili suggested.
There are some exceptions raised at the time of failure:
org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: While executing the action, an exception occurred
Caused by: org.eclipse.core.commands.ExecutionException: While executing the action, an exception occurred
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.findConstructorParameterNames(InternalCompletionProposal.java:257)
at org.eclipse.jdt.internal.codeassist.InternalCompletionProposal.findParameterNames(InternalCompletionProposal.java:1456)
at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.appendUnboundedParameterList(CompletionProposalLabelProvider.java:113)
at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createMethodProposalLabel(CompletionProposalLabelProvider.java:272)
at org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider.createStyledLabel(CompletionProposalLabelProvider.java:570)
at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.computeDisplayString(LazyJavaCompletionProposal.java:262)
at org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal.getStyledDisplayString(LazyJavaCompletionProposal.java:238)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.handleSetData(CompletionProposalPopup.java:841)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$24(CompletionProposalPopup.java:831)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup$3.handleEvent(CompletionProposalPopup.java:593)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Table.checkData(Table.java:1166)
at org.eclipse.swt.widgets.Table.wmNotifyChild(Table.java:6749)
at org.eclipse.swt.widgets.Control.wmNotify(Control.java:5534)
at org.eclipse.swt.widgets.Composite.wmNotify(Composite.java:1896)
at org.eclipse.swt.widgets.Control.WM_NOTIFY(Control.java:5086)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4584)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1627)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2069)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4989)
at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2440)
at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:564)
at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:430)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4623)
and it goes on, I don't know what is the convention for posting long stack traces
I had the same. Windows -> Preferences -> Java -> Editor -> Content Assist -> Advanced. Make sure "Java Proposals" checkbox is ticked at default content assist list (1st panel of the pop up).
By clicking "Restore Defaults" button at the bottom "Java Proposals" could be checked automatically.
Go back to the Advanced Content Assist preference page and Restore Defaults. Close the dialog using the OK button.
I had the same problem. Actually I had the content assist pop up, but that was smaller than a couple of pixels.(Who shrunk this and why was it shrunk no idea whatsoever...)
But if you see something strange(in my case, that was the letters 'Rp', but I guess it can be anything) where normally the content assist should appear, try to expand it, and you might get it back. Good luck.
None of these answers helped me: Java Proposals was ticked, and restoring defaults didn't do anything. It started working only after I restarted Eclipse.
Windows -> Preferences -> Java -> Editor -> Content Assist -> Advanced ( Java Proposals) need to be choosen.
What worked for me was to create a new workspace and copy all the projects to that workspace. The issue now only occurs on the previous workspace.
I think you are running into a known defect in 3.6. see here
try to download a newer release- it is fixed since 3.7
[edit] I just realized that you've wrote 'Juno'- are you using the latest (4.2.2)?
I just fixed the same problem in Juno switching workspace and then switching back. Other solutions didn't work.
I had the same problem but in only one particular file in my project (completion worked fine on other files). I'm also using Eclipse Juno.
I fixed the problem by removing some warnings due to unused imports in the file where completion failed... and it started working again!
This checkbox "java proposals" will be ticked until I have failed and got "No completions available". After that, it will show as unticked the next time I am opening the settings.
Go to
Eclipse → Preferences → Java → Editor → Content Assist → Restore Defaults
and then
Project → Clean
I couldn't expand sysout this morning. After a couple of wasted hours, I found that I was trying to put System.out.println() outside a method. When I did it inside a method, it all worked perfectly.
I had the same issue just now with Eclipse version 2019-06 (4.12). For me a Project clean solved the problem.

Categories

Resources