I've just created a project on Eclipse and imported some source files (existing project). But I can't compile it ! Ok, the project has got several source files, so I wanted to compile only the Main.java file (with eclipse not in the command line, in the command line it worked!) but all what I get is this error :
http://www.screencast.com/users/Amokrane/folders/Jing/media/82d772dd-10cd-4552-b1d0-3cf18bf39f13
As you can see the Main.java file is straighforward, just a hello world !
What's the matter ?
Thanks
"Unresolved compilation problem" means that the class hasn't compiled successfully. Eclipse will still let you run code that doesn't compile, but any of the specific bits which don't compile will throw this error. Look in the "Problems" tab to see what's wrong.
From the look of the Package Explorer view, every single class has a problem... perhaps the file location doesn't match the package declaration? That would match the position of the pink box just to the right of the vertical scrollbar for the class - it suggests that the error is right at the top of the file, which is where the package declaration would be.
You have a compilation error at the top of your Main.java file, just out of sight in the screenshot. Probably an unresolvable import or a wrong/missing package declaration.
It is simple in my case that the imported project needs 32 bit jre to run but cannot be compiled in the same. In IDE, if you click run, it will try to compile and run the project in single shot so fails due to 32 bit jre for compilation with the above reported error.
So i used 64 bit compiler and started to run and got compiled successfully but thrown error that needs 34 bit jre for some of the SWT used in the project. Again i changed the 32 bit jre and run the project, it is gone ! THE ERROR IS GONE NOW !
You can get the error "Exception in thread "main"
java.lang.Error: Unresolved compilation problem:" if your public class name differs from your file name.
example:
File Name:
ServiceRequest.java
Inside file, class is named differently; like
public class Service
Related
I get this message in the console when trying to run a basic program.
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/edge/EdgeDriver
In the picture it clearly shows that i have the class available in my referenced libraries but it is not being picked up during execution.
Picture of Eclipse window
Well, I did some test and reproduced the problem. Something like this.
The cause of the problem might be this: You added the jar packages to the modulepath instead of the classpath. Just adding them to the classpath fixes this issue:
NetBeans docs at http://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html say:
If the build output concludes with the statement BUILD FAILED, you probably have a syntax error in your code. Errors are reported in the Output window as hyper-linked text. You double-click such a hyper-link to navigate to the source of an error. You can then fix the error and once again choose Run | Build Main Project.
However, in NetBeans 7.0.1, the hyperlinks are mostly missing. (I'm running in Linux Mint 12.) The errors are plain text and navigating to them is a pain. This is true for all errors except for two at the end which are hyperlinked. The two that are hyperlinked are of no immediate use to me. They are:
/home/user/Workspaces/MyApp/client.git/nbproject/build-impl.xml:603: The following error occurred while executing this line:
/home/user/Workspaces/MyApp/client.git/nbproject/build-impl.xml:284: Compile failed; see the compiler error output for details.
All the places I need to edit in the code are mentioned by file and line number, but are not hyperlinked:
MyApp.java:40: cannot find symbol
symbol : constructor MainView(com.example.desktopclient.MyApp)
location: class com.example.desktopclient.MainView
MainView mainView = new MainView(this);
Does anyone know anything about this issue. I searched but didn't find anything relevant.
EDIT: I'm NOT looking for help with the code errors! I want to find out why NetBeans isn't working correctly.
I have recently been getting this Java compile error every time I try to compile code that creates an instance of a class that I have created. I've tried compiling manually, compiling from a different location, and even tried compiling in safe mode. I have also completely reinstalled Java on my computer. Here's an example of code I write and the error I always get:
Instance creator class:
public class Nothing {
public static void main(String args[]) {
Can World = new Can();
}
}
Instantiated class:
public class Can {
public Can() {
System.out.println("Test");
}
}
The compile error:
Nothing.java:4: cannot find symbol
symbol : class Can
location: class Nothing
Can World = new Can();
^
Nothing.java:4: cannot find symbol
symbol : class Can
location: class Nothing
Can World = new Can();
^
2 errors
Someone who knows Java better than me has tried to compile files that I have had problems with with no success. Also, when I run the code from within Eclipse, my IDE, it runs like it should.
Any suggestions at all or solutions would really, really be appreciated. I would really hate something like this to be the thing that prevents me from programming. Thanks again.
EDIT: I used to be able to compile the classes like this, until only recently I started receiving this error. I am compiling using an external tool I have created in the Eclipse IDE, but I have also tried compiling simply by navigating to the directory the two files are in in a CMD window and used javac Nothing.java yet the same error arises. I have also tried compiling Can.java first (which compiles), and then Nothing.java, but this fails as well. Here is the text that I get when compiling from a CMD window:
02/09/2011 06:44 PM <DIR> .
02/09/2011 06:44 PM <DIR> ..
02/09/2011 03:45 PM 289 .classpath
02/09/2011 03:45 PM 382 .project
02/09/2011 03:45 PM <DIR> .settings
02/09/2011 06:00 PM 75 Can.java
02/09/2011 05:49 PM 102 Nothing.java
4 File(s) 848 bytes
3 Dir(s) 64,669,216,768 bytes free
C:\Users\Alex\Mindstorms\NXT\leJOS NXJ\Moment>javac Nothing.java
Nothing.java:4: cannot find symbol
symbol : class Can
location: class Nothing
Can World = new Can();
^
Nothing.java:4: cannot find symbol
symbol : class Can
location: class Nothing
Can World = new Can();
^
2 errors
The problem is that you need to have an appropriate import statement (if in separate packages), and you need to run the Java compiler from the appropriate directory. Supposing your directory structure looks like:
src/
com/
yourdomain/
example/
Can.java
Nothing.java
Then you would need the following at the top of both your *.java files:
package com.yourdomain.example;
And you should put the following import statement in Nothing.java (technically this is not necessary when they are both in the same package, but is necessary when in separate packages, and it's a good habit):
import com.yourdomain.example.Can;
And then you would invoke the compiler from within the src directory as follows:
javac com/yourdomain/example/*.java
And you could then run this program using:
java com.yourdomain.example.Nothing
By the way, you really shoudn't be building projects by hand this way; you should use an automatic build system such as Maven or Ant. If you create your project using the NetBeans IDE, aside from giving you simple "Build", "Run", and "Build & Run" buttons plus all sorts of nice IDE features (code highlighting, incremental compilation and suggestions for fixes), it will generate an Ant build project for you.
Edit
Based on your updated question,... note that Eclipse's compiler is distinct from javac. If you installed javac using Cygwin or if you've been sharing your files between Windows and UNIX (possibly through a version control system), you may have run into an encoding issue. I would suggest resaving those files in UTF-8 and running unix2dos (or vice-versa if you installed javac via Cygwin) and recompiling. If that doesn't work, it might be worth reinstalling javac. Failing that, there's always Ubuntu ;).
By putting the code you've presented for each class into separate files (named Can.java and Nothing.java, of course) and having both files in the same directory they compile for me using the command line compiler:
javac Nothing.java
The error indicates that the compiler can't find the Can class when compiling Nothing. Do you have both files in the same directory?
I have figured it out. As it turns out, I had tried setting up an older version of Lego Robotics with Java on my computer, and I had created some environment variables to go with it. One of them was the CLASSPATH variable. I am pretty confident that Java was trying to read that variable (which I was no longer using) to look for my classes. Once I deleted it (and the other old variables that I wasn't using), restarted my computer, and reinstalled the JDK, everything works.
Thanks for the help from everybody though :)
I am developing a Java project using Eclipse. The project uses another project called engine, which I have added in my project build-path. As I need to call a dabo class, called House, in one of my project class, named Window, I have used the following code as usual:
import ee.asus.kernel.House;
I got however the following error in compiling time:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import ee cannot be resolved
House cannot be resolved to a type
House cannot be resolved to a type
House cannot be resolved to a type
at main.ee.asus.GUI.FrameWindow.Window.<init>(Window.java:10)
at main.ee.asus.GUI.StartApplication.main(StartApplication.java:13)
It's worth to point out that my prject and the dabo project use the same directory/packages names. Does anyone have a clue where the error may be?
The error can't resolve the first part of the package name: ee. Are you sure the package starts with ee? I see your Window class package starts with main.ee, does your engine project start with the same package structure?
I sometimes get weird behaviour with missing class files etc. when Eclipse is out of sync with the filesystem.
You could try refreshing all of your projects and doing a full rebuild.
I have been experiencing the same problem. I have an app A1(tablet version app) calling another app A2(phone version app). Upon calling, I see the same error message:
java.lang.Error: Unresolved compilation problems:
The import xxxxx cannot be resolved
xxxx cannot be resolved to a type
xxxx cannot be resolved to a type
xxxx cannot be resolved to a type
After poking around for a while, I realized the problem was the A2 doesn't run on tablet at all. It's weird because the immediate previous version of A2 runs perfectly on the same tablet(I have been on board only for 1 month). So I decided there was something wrong in the build config.
Finally, I fixed the problem by changing the order of Java Build Path. Although I have no idea why it worked, hopefully this will shed some light on your problem.
Look for the House class in your second project, opens it and see what package it is in.
(line "package xxx.yyy.zzz;" at the beginning of the House.java file)
Then make sure your Window.java file (class main.ee.asus.GUI.FrameWindow.Window) does have the line "import xxx.yyy.zzz.House;" in it.
In my case it was a version conflict.
I'm using maven and updated many packages and bumped versions of many projects. Maybe the reactor built mixed something up, or the transitive dependencies weren't up-to-date, or it was a change in a project without a version increment. However, rebuilding that project explicitly via maven fixed the problem.
Edit: When I think about it, it might also have been a conflict between eclipse's auto-build and building via maven on the command line.
We have a package that ends with exception e.g.
package a.b.c.exception;
Our code base had no issues up till eclipse 3.3, however when we shifted to eclipse 3.4, it started giving errors related to this package:
"The package a.b.c.exception collides with a type"
When I refactor the package name to a.b.c.exceptions, there are no issues. Is this due to a bug in eclipse 3.4 or is there some setting to rectify this behavior?
It's because you have a class named exception (with a lower case "e") in the a.b.c package and a package named a.b.c.exception.
It causes a name collision because if you have the code a.b.c.exception.doSomething(); - does that mean you want to call the static doSomething() method in the a.b.c.exception class? Or does it mean there's a class called a.b.c.exception.doSomething that you're trying to invoke the constructor of?
Stick with the Java naming conventions - packages all lowercase, classes starting with an uppercase and camel-case after - and you'll never see this problem.
==========EDIT==========
This is the only legitimate reason this error should be showing up...
It doesn't have to be in your project directly, it could be in another project or library that your project depends on. This should show you any occurrences of the class anywhere on the build path or your project : Hit the Flashlight looking button in the Eclipse toolbar -> Choose 'Java Search' -> enter a.b.c.exception in search field -> select 'Case sensitive' -> select 'Type' in 'Search For' -> make sure all options are selected for 'Search In'.
Are you using any tools that generate classes? Could they be putting them into the build directory of your project? When you see the error, if you go to the project's build directory, and go down into the a/b/c/ directory do you see a .class file for 'exception'?
Of course Eclipse in general could have a bug (though I'd expect there would be a bug report in Eclipse 3.4 and you'd be able to find more complaints if it was...), your Eclipse install could be broken in some way (Can anyone else open your project in Eclipse 3.4? Could you do a clean Eclipse 3.4 install in another directory? Does the error appear there?), or your project could be messed up in some way (Create a new project with no dependencies other than the JDK, create the a.b.c.exception package in your new project, create a class in your project to import a.b.c.exception.*; and see if the error occurs.).
In Java you can not have a class name that is the same as a package name.
That means the JDT package must have enforced that rule only in 3.4
See bug 63668 for instance.
As Nate comments:
A class named Exception won't prevent you from creating package exception.
Case matters.
Also remember the full name of a class includes the package it's in.
So a.b.SomeClass (class name) is different from x.y.SomeClass (package name).
There would be no name collision here.
The class name and the package name have to match in both case and package to cause this error.
See his more accurate answer.
I encountered a similar problem in a huge code base that I inherited. It turns out that the clash was caused by an partially qualified class name in a JavaDoc link.
To paraphrase, Eclipse was telling me that I had a package/type clash for a.b.c.d. when compiling a.b.c.d.London. Doing a java search on the code for a.b.c.d revealed that Eclipse thought that a JavaDoc comment in a.b.c.Paris was a match. The JavaDoc comment contained {# link d.NewYork}. When I changed the it to read {#link a.b.c.d.NewYork} the compilation error was resolved.
It should also be noted that NewYork was not imported into the Paris class as it only appeared in the JavaDoc comment. This also made it un-resolved in its abbreviated form and clicking on the link in the comment did not work. Making it an absolute reference also makes the JavaDoc link work.
I know this will sound silly, and possibly too simple to be true, but I solved this exact same error message by:
Deleting the entire line of the package name causing the error message.
Saving the .java file(this triggers a new error on the same line stating "The declared package "" does not match the expected package"), which it should do.
Re-typing the original package name onto the same line.
Saving the .java file.
Could not tell you why this worked, but it did, and Eclipse stopped throwing a tantrum on the spot.
Safe typing and speedy coding.
-Goodge
I changed one of the compilation option in eclipse and the problem disappeared.
Under workspace properties:
Java Compiler -> Errors/Warnings ->
Change 'Unused import' from 'Warning' to 'Ignore'.
If you have a class Foo, you cannot have a package that ends with Foo, such as com.my.Foo.
Also if you are using maven style, you have resources in your project under something like src/main/resources
The folders in your resources also have a package style and there, also, you cannot have a folder that contains the name of your class.
you will definitely encounter this problem when developing a Jenkins plugin according to the recommended conventions.
if you follow the Jenkins conventions, and you create a builder in a class named MyBuilder in package x.y then you are also supposed to place your .jelly in a resource folder named x.y.MyBuilder. This will result in the above problem.
However, if you name your resource folder x.y.myBuilder (notice lower case 'm' in myBuilder), unlike the recommended convention, the plugin will still work as you intended