I have a habit when writing code:
If I want to write a code block inside a {}, I will type {} first, then move the cursor into between { and }, press Enter and write my code.
In IntelliJ IDE, after I press Enter, IDE auto break and format for {} for me to write code (see this image with green arrow).
With Netbeans, it doesn't work like that (see the image with red screen).
My question is how to setting Netbeans IDE to work like IntelliJ to convenient for me to write code.
I have never written in NetBeans before. But I can understand you - it is so inconvenient and painful.
I have been going through all the combinations and haven't found the one needed.
The options that might repeat this behaviour somehow include:
Typing a { and pressing the enter. Code completion will automatically add the second brace and put you in the right place.
Using the combination cmd+enter and enter.
Then I figured out that we can write a macro:
split-line insert-break
The result:
Unfortunately, the macro is contextless. We can't write the condition "if the caret is between braces do our action otherwise, do the standard one". So, it can be assigned to another hotkey (not enter) to make enter work correctly in its cases.
It is hard to describe so see this GIF:
When I press space to continue typing, Eclipse Java editor decides to delete the second half of a parenthesis pair. I can press ESC to prevent this, but it is annoying.
I must have missed/tweaked some settings without knowing it, because in my working station, same as in my home, I am with Eclipse Mars 2 and I had never seen this.
It also happens if I press ; to end the line, and there is a parenthesis before the ;.
What should I change in Preference to stop it?
This is is a overtype mode in eclipse.
To disable it, press the Insert/Ins key on your keyboard and let me know if it helps.
I have a problem whenever I use the Scanner class in my java code:
Say I type
Scanner in = new Scanner(System.in)
As soon as I press the semicolon, it becomes/autoformats to this:
Scanner in = new Scanner(System.in;
This is the only case where this issue occurs, I have never seen it happen anywhere else when coding. I also haven't found anything in the autoformat preferences that sounds like a solution to this.
I would like to know how to fix this.
I can reproduce this behaviour both in Eclipse Mars and Eclipse Neon, and for me it looks like a bug.
In particular, when I press ) to over-type the auto-inserted ), the content assist window suggesting System.in stays open, and ; then selects it and eats the ).
Therefore I opened a bug report for it:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506729
To work around it (until it is fixed), you can disable one of the involved features: auto-inserting closing parenthesis, content assist (i. e. auto completion) or that content assist triggers on typing a semicolon. (All of these are available in the global preferences unter Java -> Editor). Alternatively you can live with the bug and close content assist either by accepting System.in with Enter, or by pressing Esc any time after the suggestion window opens but before typing the semicolon.
I have two problems.
First when i type code, netbeans automatically completes the brackets. Now what i need is to move cursor out of brackets to type the semicolon. I have to do it with the right arrow key, but i have seen tutorials in which coders to it faster. Is there some other short key or a way to do it quicker i.e from the keys under my hands?
Second the Netbeans suggestion are quite slow in my machine. Is there a way to make them load faster?
Also, CTRL-; adds a semicolon at the end of the current line, without moving the cursor. The shortcut can be changed: Menu Tools -> Options -> Keymap and search for "Complete line".
There is also in the keymap an option for "Complete line and create new line", which does the same but then puts the cursor at the start of a newly created line below. By default, I had no mapping to it, but I added it as CTRL-SHIFT-;.
Type the closed backet. Netbeans realizes what's going on and does exactly what you describe.
I'm using Eclipse to code Java (for Android) and I'm trying to debug the code as I normally do (i normally do C# though).
From what I can tell, debugging in Eclipse is really bad. I don't know if I'm doing something wrong, but it seems to be just awful.
This is the code that is being run, I get some sort of exception and I want to see what the Exception is, by breaking in the "catch"-clause and viewing the variable "e":
try
{
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService( Context.CONNECTIVITY_SERVICE );
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo.State state = mobNetInfo.getState();
}
catch(Exception e)
{
Log.v("MyAp", e.toString()); // I break on this line, and want to see what e is
}
The problem is that I cannot see "e" by holding my mouse over it (as I can in my beloved Visual Studio).
Now, I know that I can bring up the tab "Variables" which lists all variables accessible from when I'm breaking, but that's not optimal.
Just so I know - Eclipse has no way of "hovering" over the variable you are interested in, as in Visual Studio?
Edit
Thanks for the answers. However, still have the same problem =(
Go to Preferences-> Java-> Editor-> Hovers and tick the box 'Variable Values'. If you want Hover to happen automatically then leave the Key Modifier section blank.
There seem to be bugs in Eclipse related to this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=317045
https://bugs.eclipse.org/bugs/show_bug.cgi?id=330061
https://bugs.eclipse.org/bugs/show_bug.cgi?id=286237
So, yes it is supposed to work, but it doesn't always. I'm having this issues on some classes. It seems to be consistent which classes work and which don't, probably related to what jar the class is coming from etc, but I have no real clue as to what causes it. Would love to see some reproduction scenario.
You can also highlight the variable, right click, and choose to watch it. Then it shows up on the watch tab. You can also set automatic break points that trigger on the exception being thrown rather than at a particular line of code. There is not 'hover' option to view the variable as in Visual Studio in recent versions of Eclipse.
This might seem a bit strange, but do you know that the code window has focus? I have observed that sometimes the appearance of the tooltip depends on whether a view has focus or not (which I guess is an SWT bug).
I have also found that in the "Debug" view (the tab with the little green bug as an icon) where it shows all the threads, Eclipse sometimes doesn't show the variable's values if the currently breakpointed thread isn't selected.
If anyone else runs across this problem, then you might have hit a breakpoint, but the currently running thread isn't the one highlighted in the "Debug" window.
As far as I can tell, you have to be in Debug view in order to hover over objects and see their properties. At least that's how my copy of Eclipse 3.4 works.
Of course, you also need to be in Debug view to have the Step Into, Step Over, Continues, etc... buttons...
Go to Preferences -> Java -> Editor -> Hovers, and click Restore Defaults.
Found it, Goto: Preferences > Java > Editor > Hovers - Javadoc (click on it and remove the ctrl+shift keys from there), then it should work normally.
I think that the correct answer is the #RogerThomas one.
Go to 'Window' -> 'Preferences' -> 'Java' -> 'Editor' -> 'Hovers'
Then check 'Variable Values'.
If the 'Variable Values' option collides with 'Combined Hover', uncheck last one or configure new keys for it.