Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot find symbol" errors in NetBeans

Tags:

maven

netbeans

I work on a school project using NetBeans 7, Maven and the NetBeans Platform. The project has been created using the "Maven/POM Project" project template. It is a multi-tiered "enterprise" application that uses several modules (model, integration, bussiness, presentation, the rich client application itself and couple of others).

There are dependencies between these modules (but no circular dependencies). The problem is, either Maven, or NetBeans, keep getting confused. There are several types of problems which appear semmingly without any trigger. I have to keep recompiling the modules, closing and re-opening NetBeans, clearing NetBeans cache, removing and readding the dependencies and so on to temporarily remove the issues. I keep having these problems with two different installations of NetBeans on Windows XP SP3 and Mac OS X.

The symptoms are:

1) Sometimes NetBeans decides that none of the classes imported from another module exist (and I get the cannot find symbol errors. This happens repeatedly, sometimes to modules I have succesfully compiled seconds ago. Most of the time, recompiling the dependency doesn't help. The necessary dependencies are declared in the POM, the jar files exist, and if I expand them in the project view, I can see the classes in question.

2) Sometimes NetBeans decides that a method of an imported class doesn't actually throw an exception it declares to throw. Since the calls to such methods are usually surrounded by try blocks, NetBeans display error with the message a.package.SomeException is never thrown in body of corresponding try statement. If I don't remove the try block, the module doesn't compile because of NetBeans. If do remove the block, the module doesn't compile because of Maven (Maven, for some reason, can see the exception, and complains that it's not caught). This also happens repeatedly, I am not quite sure how to reliably fix this one.

At this point, the problems with Maven and NetBeans are so bad I cannot actually work on the project. If I didn't have to use NetBeans and Maven, I would have been back to vim and Makefiles by now. Does anyone at least recognize these problems?

EDIT: I've submitted the project, got 30 out of 20 points for it for some extra work I've done on it, and until it leaves the alpha stage, I hope to never have to work with NetBeans again.

like image 245
Honza Avatar asked Jan 22 '12 12:01

Honza


People also ask

How do I fix error Cannot find symbol?

In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.

Why is Java saying Cannot find symbol?

Misspelled method name Misspelling an existing method, or any valid identifier, causes a cannot find symbol error. Java identifiers are case-sensitive, so any variation of an existing variable, method, class, interface, or package name will result in this error, as demonstrated in Fig.

What does Cannot find symbol error mean?

Any error that starts "cannot find symbol" means that the compiler doesn't know what that symbol (which can be a variable or a class name) refers to. In the second line of the error, where it says "symbol: class Scanner", that indicates that it doesn't know what the Scanner class is.

How do I show hints in NetBeans?

It is easy to enable Java hints in NetBeans. Select "Tools" from the title bar, then select "Options" from the drop-down menu. Choose the "Editor" option and then select the "Hints" tab.


1 Answers

I had a is never thrown masking a cannot find symbolin a multi-module maven project in Netbeans 7.0.0

The symbol in question was a class in another module under my maven master project.

I refactor/renamed the class that wasn't being found - this fixed the issue. I then renamed it back - the issue remained fixed.

Not ideal by any means, but figured I'd share.

like image 141
Glenn Barnett Avatar answered Sep 18 '22 15:09

Glenn Barnett