Eclipse - Disabling compiling of XML files while in Java perspective - java

When compiling android stuff in eclipse, I am forever annoyed when I hit the "Run" button to compile and run, if I am in a .java file everything works great if im in an .xml file (for android layouts) it compiles the xml file and produces an _out.xml file which screws up the project so that I first have to delete the "out" file then clean my project files.
Any quick answer on how to disable the compiling of xml files?

Samuel has told already a solution. What I prefer is to use the "always run the last project" setting.
Go to window -> preferences -> Run/Debug -> Launching and than activate the option on the bottom labeled: "Always launch the previously launched application"
If you have multiple projects you will sometimes have the issue that you start a project you didn't meant to start. That will occur only once, because after starting the right project, you will stick to that until you switch to the next project (which shouldn't happen very often on a working day).
Its not a perfect solution, but prevents the mentioned issue with, in my experience, the lowest/smallest (whats the right term?) side effects.

There is no way to do this, the reason it happens is because of the fact that when you click "run" it's trying to run the .xml instead of the Project its-self. The easiest thing to do to avoid this, is when you go to hit run do a Ctrl+s, then click on the project folder, then hit run, or do the same thing, but switch tab to a .java file. Sorry to be the bearer or bad news, when I started I had the same problem.. drove me crazy, but when you get into the new habit, you're just fine!

Related

Intellij "go to > implementation/declaration" navigation feature not working

I have a maven java project that I would like to use IntelliJ for development on. One of my favorite navigation features of IntelliJ is the 'go to > implementation' feature that appears when you right click on a method or function.
My problem is that this feature is not working for me; when I choose it nothing happens, no error, it just sits right where it is. It also isn't suggesting functions and methods as I type, so it's as if IntelliJ is failing to recognize dependencies and relationships among the various classes in my project.
I know the code is fine because it compiles and runs, has anyone else experienced this? I made sure to open the project as a maven project using the pom.xml file but that made no difference.
Right click on the root folder of your project (Application code folder)
and
select -> Mark Directory as -> Sources root
It seems that the index is wrong.You need to force reindex the project files.
Just try:
File -> Invalidate caches...
Then restart your IntelliJ
This is way too broad of a inquiry!
There's a few things that could be wrong but compiling and running has nothing to do with it. Compilers such as maven can generate sources or modify behaviors of compilation units and can be considered non-deterministic programming which because of its very essence, can't be analyzed.
You're referring to a Contextual IntelliSense operation; in the context you're in currently, dependencies etc may not be properly configured. You can't know what you don't know; similarly, Intellij can't either. Make sure all libraries are listed properly within the Project/Global -> Libraries section in order to have them properly function.
Alternatively, your cache could have become corrupted. Try File -> Invalidate Caches / Restart...
Lastly you could simply have the option disabled somehow. There's various settings which will disable the option. For example, Power Save Mode may be enabled. For the rest I suppose it'd be best to refer you to the help documentation.
I had the same issue with idea and i did:
"Mark Directory As > Sources Root" not worked.
"Invalidating cache and restart not worked"
"Deleting .idea and .iml files not worked"
Finally right click on pom.xml and select "add as maven project" worked for me.
Ishnark's comment on my question provided the solution I needed, reposting here so that it can be upvoted and hopefully help others. All I needed to do was right click on the source root of the projecet and select "Mark Directory As > Sources Root". More details here:
solution
In my case the problem was the next: for some reasons *.py files were registered as a text files, not python ones. After I changed it, code completion started to work again.
To change file type go Preferences -> Editor -> File types -> add *.py into Python again.
comment from: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360005050480-Cannot-find-declaration-to-go-to-solved-
GO TO File>New>Project From Existing Source then choose you're project
let maven build you're project again.

Intellij doesn't show run button

Intellij doesn't show run button even if that file is in src folder.
Maybe do you know what to do?
P. s. It's strange because that file used to show run button but after recloning git repository it just doesn't show any more.
Right click on src directory and select option Mark Directory As > Sources Root.
There is an Intellij bug that will result to an intermittent disappearance of that little tiny green run button on the left side of the source code (on same column where the red circle breakpoints are). Yes, you can right-click on the mouse and can do the run via the menu, BUT we love that tiny green button so bring it back!! From time to time, i see this green friend and then suddenly it vanish mysteriously and comes back again. I did all, such as rm -rf .idea and other weird stuff, but no explanation has ever been achieved to explain the vanishing green button and it's sudden re-appearance intermittently.
I am drafting this answer, because all of the above answers seems to claim that there is a logical explanation of the intermittent disappearance of our little green friend and that a sequence of steps exists to make our little green friend re-appear, when in fact, there is no such steps and we just have to accept this is a bug to save the remaining hairs in our scalp.
In my case Run/Debug buttons disappeared for all projects after updating from IDEA 2019.2 to 2019.3. Tried checking Sources Root, Invalidate Caches, Run/Debug configurations etc - no luck. Only restoring Run/Debug action group helped:
Right click on main toolbar (where the button disappeared) > Customize Menus and Toolbars... > select Run/Debug > Restore Run/Debug.
I got the same problem with intellij 2019.3 and 2020.1 and found the solution here : https://youtrack.jetbrains.com/issue/IDEA-228180.
Basically, in the IDE the buttons run/debug and the error detection in the code were missing.
The fix was to disable the plugin 'Gradle' (I don't need it anyway) :
Settings > Plugins > Gradle and click disable and apply.
After restarting your IDE it should work
I had this issue when building a microservice with SpringBoot.
I added a new microservice into the root folder and I could not run it.I am using Maven.
Step:
Open pom.xml
right click and select "Add as maven project"
It should resolve it immediately but you can reload the IDE if it does not update immediately.
IDE: Idea 2021.2.3
Build tool: Gradle
I removed the .idea and reimported the project from the Gradle source. Worked fine after.
Another reason could be the Highlighting Level set to None, it should be set at least to Syntax.
First, make the folder as source root.
Second, make sure you set the project’s sdk correctly. For example, if you set the sdk correctly then import java.util.Scanner can be analyzed by IDEA.
Tip:
try not setting the SDK to IDEA’s bundled JDK. I set the project’s SDK to JDK 11 bundled by IDEA at first then found it couldn’t resolve import java.util.Scanner. Setting to JDK 16 which is installed by the OS’s package manager solved this problem, then the “run” button showed up.
If IDEA can index a java file then the file icon will show with a small “c”, indicating a java class. If not, the file icon will show with a small “j”, as this problem’s image shows, indicating a java file which IDEA doesn’t index.
In my case there was a plugin (springboot helper) which I had to disable.
Reinstall the IDE, it solved my problem.
I also applied all these methods but it still didn't work so I stopped my window firewall and allowed access for this application. I don't know how it worked out for me but it just got displayed on top of my screen that window defender firewall has stopped some of this app's features and there was an option to allow so I clicked on it and it now works just fine.

Java files disappeared in Eclipse after exporting

I was working on a project in Eclipse that has several classes and one Interface. I decided to export it as a jar so that I can run it on another machine.
This went just fine. However, when I went back to Eclipse, it suddenly removed all of my file one by one as soon as I tried to edit one of them. Now there is only one file left and it's not even my main. I had everything in the default workspace directory and now only that one file remains.
Can I undo it?
Something similar just happened to me a while ago, Eclipse has the option to recover files no matter if you have a version control or not...
make right click in the project and make a "Restore from local history"
a new window with all accidentally removed files will appear and you can undo the mess :)

Eclipse does not refresh project files in package explorer view

Today I see a strange behaviour of Eclipse 3.5.2 for the first time in 3 months.
First, when I run a main function, it runs a previously compiled version. Let's say I press Ctrl+F11 in the window with an open java class and existing main function. Usually it rebuilds the class and runs a new version. Today even if there was a compile mistake, it would run fine. So I guess it does not recompile the class.
Next, more strangely, if I intentionally make a mistake in the code and Eclipse underlines those lines in red, still the project Explorer does not mark them as containing errors. They remain of grey color if there were not any errors.
First I did not know how to solve this problem. I tried to reopen the project, restart Eclipse and finally reboot the OS. After the tenth attempt, after rebooting, Eclipse said that all project's files are "OUT OF SYNC with the file system". When I pressed "Refresh" - F5 on a project's header name in Project Explorer it finally marked all the files with errors as containing errors and running the main function gave the desired result.
An hour of my work passed and this happened again , with the other project. All the same. No marking of files as red, running no matter what old version of class with no compile errors.
And since Eclipse does not tell that files are out of sync, simply pressing F5 on a project cannot help.
What can you suggest?
When you select a project in the Project Explorer view and press F5, Eclipse should traverse the entire directory tree for the project checking that all files and directories all in sync. It does for me ...
The only thing I can think of that would cause this not to work is if you have file system timestamp anomalies. For example, if a file in the file system is updated but the file's last-modified shows that it was updated in the past. This kind of thing can happen if your machine's system clock is moved backwards or forwards at an inconvenient time. If you think this might have happened, try closing all projects, restarting Eclipse and doing another F5 refresh.
(I used to run into Eclipse synchronization issues a lot, but I put that down to a combination of flakey plugins and doing builds from the command line. Either F5 or Project>Clean usually works for me.)
It is also worth checking that you haven't turned off "Build automatically"; see https://stackoverflow.com/a/2818290/139985. This is not a "refresh" problem, but it would be easy to confuse it with one.
Is Build automatically on? (Menu > Project > Build automatically)
It happened to me because there was a cyclic dependency between two projects. Each project had the other on its build path.
Solution: Reimport the project
It happened to me when checking out a new file from svn in explorer. Eclipse could not find the new file for some reason.
I tried refreshing the project(F5) and Project > Clean and build the project(Project > Build All) none of these worked for me.
So I deleted the project from the Project Explorer view(Not from hard disk). Make sure you unselect "Delete project contents on disk(cannot be undone)" checkbox and save any unsaved changes before you do this.
Now reimport the project using File > Import option. That should work in most cases.
If you use gradle, or something similar, instead of reimporting a project you can just regenerate the project files (gradle eclipse for example), and then you can refresh the project. Less cumbersome than deleting and reimporting.

Debugging with Eclipse using multiple windows

I usually run a dual-monitor setup, so I have two Eclipse windows open for the same workspace, displaying different files. When I'm debugging and a breakpoint is hit, Eclipse switches to the "Debug" perspective, but it also shows the file/line where the breakpoint is in both of my windows. This occurs even if the file containing the breakpoint was open in one window but not the other (before the breakpoint was hit).
This is really annoying.
How can I have Eclipse only show the file containing the breakpoint in one window? Ideally, it would choose which window based on where the file is open already. If it's not already open somewhere, I don't really care which window it pops up in.
You can create another workspace and in that workspace create a new project from the same src code (same files in file system) of the one in your current project in your current workspace.
That would let you stop on one breakpoint without the other window stopping their too.
Notice that after you make some code modifications in one project you'd have to refresh the other project for those changes to apply in it.
Eclipse switches to the debug perspective for all windows the debug perspective has been opened once (i.e. the little icon on the right top corner is available). If you close that perspective (switch to another perspective is not sufficient), it won't switch to it anymore on that window.
At least, that's the behaviour I observed on Kepler (I know, that question is older but just came across, maybe it still helps someone).
This worked for me:
In Window->Preferences->Run/Debug->Launching->Launch Configurations enable "Apply window working set(s)"
Personally I find this more efficient than creating two workspaces.
Closing the Debug perspective (righ-click on the little icon on the right top corner) worked for me.
I'm using Oxygen and I have the following settings in the Run/Debug Preferences:
Open the associated perspective when launching: Never
Open the associated perspective when an application suspends: Prompt
Maybe you select the sources for Debugging by "File System Directory" instead of by "Java Project". To change this go to Run=>Debug Configuration=>Add Sources=Button: ADD...=>Java Project and select your Projects.
Make sure, that the added sources are found first by moving them to the top.
To disable multiple debugging in multiple windows in eclipse, go to Windows > Preferences > Run/Debug and uncheck Activate the debug view when a breakpoint is hit

Categories