Saturday Mar 18, 2006

Why am I Using NetBeans? Top Reason

CTRL-K and CTRL-L

Two most useful key shortcuts in NetBeans, which let me quickly autocomplete any words when editing any textual files (java, xml, html, etc). Like CTRL-P in Vim, they just search the matching words in open buffers either upwards (CTRL-K) or downwards (CTRL-L). Unlike CTRL-space autocompletion, their matching is not bound by lexical scope, and therefore quicker. For instance, when I am writing this:

String unitName = null;
String userName = getUserNameFromRequest();
register(u  //STOP TYPING! Press CTRL-K to autocomplete userName

Why is CTRL-K better than CTRL-spce, at least in this example? Well, if you press CTRL-space, you will see a pop-up window that includes at least two items in order: unitName and userName. Then you have to click on or scroll down to userName to select it. That's a lot of key strokes for such a simple operation!

What if I want to use unitName at the above cursor point? You just need to hold CTRL and press K twice. As you keep pressing K, NetBeans keep going upwards in your buffers. Not just the current file, but all the open files, so you can get a variable name from other files. This is equivalent to locating the other file, finding the variable in that file, copying it, coming back to your working file, and pasting it at the right cursor point.

Since CTRL-K and CTRL-L know nothing about lexical scope, they are very flexible and versatile:

  • Faster than CTRL-space, which requires parsing AST.
  • You can use it in java comments, xml, html, jsp and anywhere CTRL-space does not work.
  • Less moving around between keyboard and mouse.

Caution: as with any autocompletion techniques, you are ultimately responsible for choosing the correct one. In the above register(String userName, String unitName) method, if you erroneously choose (unitName, userName), even the compiler won't detect it.

BTW, after you autocompleted register(userName, you can just directly type ; without movig cursor to the end. It will automatically jump to the end of the statement. Of course,the ending ) was already there when you typed (.

Friday Mar 17, 2006

NullPointerException (NPE) from FileScanner removeFromRepository?



If you see this NPE in NetBeans 5.0, it means your project source code repository is corrupted. When this happens, the code completion (CTRL-space) for JDK classes (e.g., String, System, etc) stops working. Everything else still works beautifully. But I still found it a little inconvenient, since I seldom type in complete class/method/variable names inside NetBeans. Of course, if you know all the JDK classes, their fields, methods, each method parameters, and you enjoy typing, then it may not be a big problem for you.

Fortunately, there is a simple solution. Several NetBeans developers graciously offered their help: delete this directory $netbeans_user_dir/var/cache/mdrstorage. In a typical installation, it is $HOME/.netbeans/5.0/var/cache/mdrstorage/

For more information, refer to the this issue. If you have an idea, please contribute to this great open-source IDE and make it even better.

PS: I use Google as a debugging tool: everytime I have this type of problem, I google it to see if it happens to others. However, this time Google didn't return any matching results. So I posted it here, hoping Google can do better next time whoever searches for this NPE.

The stacktrace is as follows:

java.lang.NullPointerException at org.netbeans.modules.javacore.scanning.FileScanner.removeFromRepository(FileScanner.java:194) at org.netbeans.modules.javacore.scanning.FileScanner.scan(FileScanner.java:179) [catch] at org.netbeans.modules.javacore.JMManager.scanFiles(JMManager.java:1092) at org.netbeans.modules.javacore.JMManager.resolveCPRoot(JMManager.java:1006) at org.netbeans.modules.javacore.JMManager.resolveCodebases(JMManager.java:815) at org.netbeans.modules.javacore.JMManager$2.run(JMManager.java:769) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)

About

Cheng Fang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today