0

I deleted my class files accidentally (the whole contents of the bin folder in fact, when trying to configure a git repository).

Now, when I run my program on Eclipse, I get an error:

Error: Could not find or load main class BmrMain", and no .class files are generated in the bin folder.

I can easily rebuild the project, but "Build Automatically" is enabled, so my question is why does Eclipse not rebuild the class files when I run the application? Why do I have to clean then rebuild for the class files to be recreated?

Also, when moving my .src files to a seperate folder to test, I compiled using the command prompt. It worked, but when compiling (javac BmrMain.java), the following error popped up:

Note: BmrMain.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Although the program runs correctly when typing java BmrMain. What do these errors mean? I do have some warnings in Eclipse, but they don't seem a big deal to me and consequently, I left them:

Eclipse screenshot

dimo414
  • 47,227
  • 18
  • 148
  • 244
  • To your second question, have you tried running `javac -Xlint:unchecked`? That's exactly what that message is telling you to do. – dimo414 Sep 17 '15 at 23:53
  • @dimo414 Nope I haven't. What exactly is the difference and why is it asking me to do so? –  Sep 18 '15 at 00:16

3 Answers3

0

Eclipse will build automatically when you make changes inside Eclipse. It isn't actively watching the filesystem to see when you delete file's it's build out from under it. If you muck with your project directory outside of Eclipse, you should always refresh the project, and may need to tell Eclipse to manually build as well. Otherwise, Eclipse will assume the project is in a good state (since that's where it left it).

The warning javac outputs is telling you there are bad practices in your class (unchecked casts, to be specific). If you add -Xlint:unchecked to the javac call, it will output exactly what lines are problematic.

The output will be similar to the warnings you're already seeing in Eclipse, and they are a big deal. You're using raw types, which is a very poor practice that leads to buggy, difficult-to-work-with code. Generics were introduced in Java 5, use them.

Community
  • 1
  • 1
dimo414
  • 47,227
  • 18
  • 148
  • 244
  • Ignore the comment earlier, thanks for the detailed explanation. I've fixed the ComboBox error. Now I'm confused about the serialization error. When I attempt to fix this, it asks me if I want a default serial version ID, or a generated one. I sort of know what serialization is, but I don't know how I should generate the id. When you say "refresh the project", do you simply mean clean and rebuild? –  Sep 18 '15 at 00:18
  • If you right-click on a project there's a "Refresh" option. That scans the filesystem, and will try to build any changes. – dimo414 Sep 18 '15 at 01:59
  • Thanks. This does nothing unfortunately, bin folder is still empty. –  Sep 18 '15 at 02:01
  • The serialization error is less serious (it only matters if you're using Java serialization, which generally you don't need or want to do). You can disable that warning in Eclipse, or just let Eclipse set a version ID for you. There's a number of [questions](http://stackoverflow.com/q/2288937/113632) on the site about that warning. – dimo414 Sep 18 '15 at 02:02
  • *Try* being the operative word. Stop manually deleting your bin directory. If refresh isn't sufficient, clean and rebuild. – dimo414 Sep 18 '15 at 02:03
  • As I said, it was an accident. Accidents happen. I can recover it by rebuilding, but was just wondering why Eclipse didn't do it automatically as I thought it would (which you answered previously). –  Sep 18 '15 at 02:04
  • Like I said, the answer is because it doesn't constantly monitor the filesystem for unexpected changes. That would be very expensive. – dimo414 Sep 18 '15 at 02:05
  • Yep, I got that now. Thanks a lot for the help. –  Sep 18 '15 at 02:07
0

You should avoid deleting files generated by Eclipse from "outside of Eclipse" (e.g. via the command line). Those kind of changes are not automatically noticed by Eclipse.

However Eclipse will automatically notice changes to source files of the project and then automatically re-build the necessary class files.

Also have a look at the Eclipse preferences (menu item "Eclipse > Preferences"). In the "General > Workspace" pane you will find three checkboxes related to (automatic) refresh: "Build automatically", "Refresh using native hooks or polling", "Refresh on access". All these checkboxes should be checked.

Udo Borkowski
  • 311
  • 1
  • 9
  • Those options are all checked. So what does one do if they mess with the .class files? Is a clean and rebuild the only feasible option to repair the code? –  Sep 18 '15 at 00:20
0

In my case the java builder was missing. It's probably a very specific problem that arose due to eclipse in ubuntu not being able to import a git project, but anyway, the solution was to edit the .project file, which should be located in the root folder of your project and it should look like this:

<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

So for me, adding the buildCommand lines fixed the problem.

dadah
  • 1
  • 2