Eclipse “cannot be resolved to a type” error

So I’m coding along and all of a sudden, Eclipse (3.4) can’t resolve classes. Classes that are in the same package as the class I’m editing. Classes that are fully qualified in the import statement.

Not good.

The last thing I had done was add a Spring @Autowired annotation. I saved the file and voila, everything goes to crap. I then spend a stupid amount of time trying to track down the cause. I took the changes out. I did a clean and rebuild and retest (everything passed; this was Eclipse-only). I added new classes to see if they broke (they did). I did a false modify (add space, remove space, save) to see if that broke said file (it did). It was a death spiral. No matter how I changed the code, the same problem was there.

Turns out, it wasn’t the annotation, or anything else in Spring, or any of my code, or any of my Eclipse plugins. It was a step before that killed me. I was doing a little cleanup and I created a temp directory at the top of my project folder so I could move some files there. It wasn’t nested in anything, other than the top level directory. What could go wrong?

Apparently, that makes Eclipse see red. Squiggly red.

The solution was simply to do a refresh (F5) on my project. Just as quickly as it started, the problem went away. That smells like a bug to me, but if it was I figure I’d see a lot more mentions in Google or the Eclipse bug tracker. I’m really hoping this helps someone save some time.

Update: If that doesn’t work, try:

Clean, refresh, build, restart

Also, remember any external build/clean scripts you might be using. For instance, Grails has a command line “clean” you may have to invoke. Same if you have Ant or Maven builds.

David Resnick (comment below) discovered this tip for those with an external build script:

Windows–>Preferences–>Java–>Compiler–>Building–>Output folder–>”Rebuild class files modified by others”.

This exists in Eclipse 3.5; I’m not sure about earlier versions.

Another issue I’ve found over the years is problems when upgrading Eclipse. In theory, new versions of Eclipse should update your workspace and project files just fine. In practice, they can become corrupted. My new rule is to create a new workspace for every major version upgrade of Eclipse (maybe more often if you’re cautious). Then I copy those projects and import the copy. This ensures I have a backup plan should something go awry. You may need to reimport your project(s) if there’s a problem that won’t go away after an upgrade.

Many commenters offered other solutions, so check below. Thanks to those who contributed them!

Update: I switched to IntelliJ. Click that link for details why, it’s not the usual hand-wavy “it’s just so much better” that never got me to switch. Not saying it’s bug free, but nothing is, and I’ve never seen errors like this there.

Keywords: false error, bogus error, eclipse bug

Selecting Technology Using Job Ads

In IT (as in most industries), there are many factors to consider when choosing a new technology. One must carefully consider cost, features, ease of blah blah blah who cares? The only thing that matters is: will this look good on a resume?

Enter Indeed job trends. Indeed is a job website that searches many databases at once. They have launched a nifty tool that allows you to graph job trends based on keyword; it even does comparisons.

Comparisons are perfect for choosing technologies. To do a comparison, you separate keywords with commas. You can also have multi-keyword searches by separating them with spaces. And you can quote exact phrases. Yeah, that’s not terribly clear so I’ll just give examples.

Consider the many technologies used to create rich internet applications (RIA). It’s ridiculous. You want to know what’s in demand and what’s gaining ground. I used a context keyword in my search phrase since some frameworks use common words with multiple meanings (dojo might be found in karate instructor jobs, flex in body builder jobs, etc.). So requiring “ajax” to be in the job description makes the search more relevant:

ajax scriptaculous, ajax yui, ajax dojo, ajax flex
Scriptaculous, YUI, Dojo, and Flex job trends

Here we can see that my choice to begin Flex 3 classes was freakin’ brilliant.

Since these are statistics, they can help persuade others by lying. For instance, two popular Java build tools are Ant and Maven. You want to use Maven 2 because it’s newer so it must be better. Let’s compare:

java maven, java ant
Maven vs. Ant job trends

Crap. That won’t help convince your boss. Which is bad, because the real reason you want to use Maven 2 is that you’ve heard Atlassian uses it, and you want work for them so you can move to Australia and be around sheilas with cute accents (never mind the spiders the size of small dogs). No worries, Indeed has you covered. Just change the scale from Absolute to Relative:

Maven vs. Ant job trends - relative comparison

Wow, Maven is taking off like crazy – 600% job growth! That totally makes up for Ant having 4 times as many jobs. And this technique works with every other cutting edge framework and tool. I mean, it has to; that’s just how math works. You go from zero jobs to some jobs, that’s like infinity percent increase for significantly small positive values of zero. Math doesn’t lie.

Hopefully by now you’ve realized I’m employing some tongue in cheek humor. At the same time, being able to chart industry trends is valuable for both your business’s technical strategy and your career planning. Use it wisely.

JavaScript 2: The Next Big Language?

OK, so this blog is starting to look like the Steve Yegge Fan Club, and I’m only 3 posts in. Lucky for me, I don’t care.

Steve recently wrote a compelling post on the next big language. In my first post here, I bet that Java would be dethroned within 5 years, and Steve appears to agree. Now, he doesn’t mention which language he’s talking about, but if you read the comments (those on-topic; not those wondering how he got a hot wife), it’s pretty clear he’s referring to ECMAScript 4 (ES4), aka JavaScript 2 (JS2). If you don’t think it’s clear, I suggest you actually read the article, then his other articles (including the brilliant drunken blog rants), then Brendan Eich’s presentation on JS2. [1] At this point, it should be crystal.

As I’m always on the lookout for the next language to write my masterpiece in, this launched yet another info hunting/gathering session. JS2 looks to be a pretty nice language, the syntactic love child of Java and JavaScript, with some other goodies thrown in. And I never had a big problem with JS1.x. In fact, I’ve got solid anecdotal evidence that just about everyone who hates JavaScript never bothered learning it like a real language, picking up the rhino book and reading the gory details section. The haters all see JS as an obstacle, a necessary evil thrust upon them by the need for client-side validation, so all they do is blindly stumble around, trying to twist some working script to their needs. Yeah, some haters are cunning programming linguists who hack out parser generators while waiting for their triple-grande cafe Americanos, but they’re a tiny minority. Plus, they hate all languages.

Anyway, I found out a lot. ES4 is already available, (more or less, as the spec isn’t finalized) in Adobe’s ActionScript 3 (AS3). Yes, the language used for Flash. Adobe built a virtual machine for it, codename Tamarin [2], aka AVM2. It’s been embedded in Flash 9, and it’s supposed to be wicked fast. It’s also been open sourced and donated to Mozilla, so it should show up in Firefox 3. [3] Frank Hecker wrote a nice piece on what impact this will have.

So soon you’ll be able to use the same language for Flash apps, Flex 2 apps (which is a lot more up my alley), and AJAX. That’s a big motivator to learn it.

The only place it’s missing is the JVM. Now, if you read carefully, Steve said it would launch on the JVM. Unfortunately, I’m not so sure. Rhino, the embedable JS interpreter/compiler for the JVM, can only handle JS 1.5. I figured, hey, they just added it to Java 6, of course they’ll maintain it and keep it up. But we’re up to JavaScript 1.7, and it’s still not there. So I focused my search for a Rhino roadmap, and you know what? There pretty much isn’t one. The best source I could find was this thread on mozilla.dev.tech.js-engine, concerning the implementation of ES4 features in Rhino. I found it scary for a few reasons:

  • There appears to be only one active committer, and just a few other helpers. Apparently Sun does not have any engineers devoted to Rhino.
  • Modifying Rhino to handle ES4 is a daunting task. Rhino was initially a straight port of Spidermonkey, which was written in C.
  • The other option suggested is creating a straight port of Tamarin. Tamarin was written in AS3, essentially JS2, which should be easier to port to Java than C was. But it’s 135,000 lines! And in a much terser language than Java! So who knows how many lines the port will end up being. An AS3-to-Java compiler seems like it would take less time, but that still sounds like a major effort.

I’ve also seen a couple instances (PHP, Python) where someone connected Java to a native implemenation of a language. Perhaps they could do that with Tamarin, although I wonder about the performance. Would it be better than a Java implementation, or would the overhead hurt it too much?

So I’m bummed, as I’m looking for something to help me script Java (actually, replace it in the middle – and possibly presentation – tier), but I don’t want to choose a dead platform. To use JS2 server-side I’d have to give up Java altogether, and that seems like cutting off my nose to spite my face, or throwing the baby out with the bath water, or some other such calamity. There are just too many Java FOSS libraries, which solve really hard problems, that I’d have to give up.

So I’m going to have to size up JRuby some more, and perhaps do a bit more digging on ES4, before I make any rash decisions. Procrastination wins again!

[1] BTW, the presentation uses some new HTML/CSS/JS document format to replace PowerPoint, and you have to point your mouse in the lower right to pop up the controls. Crazy frustrating if you don’t know that.

[2] It’s a monkey, like Mozilla’s C-based JavaScript engine Spidermonkey. Not tamarind, the seed that makes a delicious sweet and tangy sauce for my samosas.

[3] If Microsoft was smart, they’d use it for IE8, assuming that’s legal and wouldn’t cause Mr. Gates to have an aneurysm.

JVM Language Shootout

Steve Yegge has a comparison of various languages for the JVM. For the comparison, he creates an actual Swing application, so if the language couldn’t handle that, it didn’t get included. Since the objective was to find a language capable of replacing Java on the JVM, it’s a reasonable criterion. He’s not finished, but he goes into depth on languages he does cover. I’m sure I’m not the only one anxious to hear his opinion of JRuby. Whatever he writes about it, though, couldn’t be worse than his damning review of Groovy.

To give you a taste of Steve’s writing style, here’s something from his Java wishlist (yes, Java 5 was included in the shootout):

#2: Bean shortcuts — C’mon, Sun folks. It’s practically the first thing people change about Java when they write a JVM language (or even an interpreter like BeanShell). Even small children can tell you that accessing a property using field-access syntax beats calling a getter or setter method. The only possible explanation for why Sun hasn’t added this yet is that they hate us.

Why I chose WordPress over Roller

I thought I’d kick off this blog explaining my tech choice. I had planned on using Roller, because it’s written in Java, and many large, multi-blog systems (JRoller, Sun’s employee blogs, others) use it. I thought I could mess with the code if I felt like it, maybe learn a few things. Per my usual M.O., I donned my trusty loincloth and went on a info hunting/gathering expedition. The short of it is that Roller just wasn’t meant to be used as a personal weblog you host yourself. [Actually, it was conceived as a demo program for an article on how to harness Java FOSS to build apps.] Just look at the installation requirements and you’ll understand. It’s pretty much expected you’ll just sign up for a blog on JRoller or Java Lobby, which is admin free, and maybe you get a little exposure. Well, I felt that Java wasn’t my main topic, so I didn’t want to get lumped in there. [At some point I’ll write why I think King Java will lose it’s crown within 5 years.] And I wanted my own domain (which is awesome, you’ll agree).

I went through something similar with the last blog I set up, looking for a content management system with all the features I wanted. I got very hung up on all sorts of security requirements, probably because my day job involves tons of that in our web apps. That and my fear that a potential client or employer will discover I actually have opinions, and decide I’m too much of a risk to hire. Then I remembered that public content was the whole point of a blog, and if you don’t want your mom reading it, you probably should just leave it – or your real name – out of your posts. Another time saver: remember that as long as basic usability is followed, users (readers) don’t really care about presentation. I’m lauching a blog, not WiReD Magazine or the next social networking service. [I might also launch those things someday, but not today.] Back then I settled on Movable Type for ease of use.

Now I’m settling on WordPress for ease of use. I’ve set WP up several times now, and I’ve got it down to about two minutes, now that the database is set up. First time installation was five minutes (had to read the docs). And WP actually has way more features than JRoller, and a thriving plugin and theme development community. And unlike MT, it’s free . Not that MT is expensive, mind you, but my math skills have not deteriorated to the point where I can’t see a bargain when it bites me on the nose. It was so good that I converted the other MT blog to WP with reasonable success. [Note to those considering: do not skip the step where you convert the file to UTF-8 with iconv. All “special” characters like apostrophes turn into question marks. Very uncool.]

So if you’re setting up a blog for yourself, think hard about whether hacking its source is a necessity or just a phantom requirement. And if you believe it’s a necessity due to some missing feature, I bet somebody already wrote a plugin for it.