-2

I am using eclipse and i get this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:     at Wall.main(Wall.java:6)

her's a screen shot"http://postimg.org/image/ufvv9p6aj/"

Here is the code:

import becker.robots.*;
import javax.swing.*;

public class Wall
{
    public static void main (String[] args)
    {
        JFrame frame = new JFrame ();
        frame.setVisible(true);
        JPanel panel = new JPanel ();
        panel.setVisible(true);
        frame.add(panel);

        JColorChooser color = new JColorChooser();
        panel.add(color);


    }
}
  • Eclipse should not crash, but the obvious compilation error is that you put a space in between constructor call and class name `new JFrame ()` and `new JPanel ()` –  Sep 20 '13 at 00:58
  • 6
    @HowardGuo Java ignore whitespace for the most part. The syntax is correct. – tckmn Sep 20 '13 at 00:59
  • 1
    @user2797488: You have a compile error, i.e. a red underline below line 6. Mouse over it and tell us what it says. – tckmn Sep 20 '13 at 01:00
  • Please run Eclipse's formatter and confirm that this code matches exactly. It doesn't seem to have any problems. – chrylis -cautiouslyoptimistic- Sep 20 '13 at 01:00
  • In **nearly every** programming language on Earth, whitespace *between tokens* is insignificant. – millimoose Sep 20 '13 at 01:01
  • 1
    @millimoose Whitespace is not insignificant in [Whitespace](http://esolangs.org/wiki/Whitespace); everything else is insignificant :P – tckmn Sep 20 '13 at 01:02
  • This code works just fine if complied using `javac`. Comment off your becker import (since you don't use it) and try again. Verify that `javac` has no inherent problems by creating a file Wall.java, pasting in this code, and running `javac Wall.java` (after commenting off the becker line), then `java Wall`. – Mike 'Pomax' Kamermans Sep 20 '13 at 01:03
  • Which line is 6th? May be you should put entire java file. – user2259824 Sep 20 '13 at 01:04
  • The code is compiling file. – Juned Ahsan Sep 20 '13 at 01:04
  • So, I'm guessing the problem here is that Eclipse can compile even broken source code into a .class file. This class file is fine for purposes of compiling other source files against its API, but it won't actually work at runtime. So since you have an unresolved import, Eclipse will generate a class file for you that simply doesn't work but still has the classes and their methods insofar it's possible to emit them. – millimoose Sep 20 '13 at 01:40

4 Answers4

1

From the code you posted, line 6 contains no syntax error. I can only guess it's eclipse build problem, maybe you turned off auto compilation on file saving, or eclipse is looking at old version of the class files generated from your code (or maybe you haven't even saved your file)

Id suggest you save all files, and try a rebuild by doing Project -> Clean (if you set build automatically), or Project -> Build Project (after cleaning it)

gerrytan
  • 40,313
  • 9
  • 84
  • 99
1

Just create a new file and copy/paste the code there after removing the first unused import. I suspect that there may be some special characters causing that compilation error.

Rami
  • 7,162
  • 1
  • 22
  • 19
0

look here

make sure there's no error in your code. do you see any red cross marks in your code? If there is then try to put your mouse cursor on the cross and see more details about the problem.

Community
  • 1
  • 1
CodingBird
  • 705
  • 2
  • 11
  • 22
0

Your problem is that becker.jar is just listed in your source folder (it is not source, it is a compiled jar and therefore should be in a lib folder, and then added to the Build Path). Eclipse can't find your import becker.robots.* because it doesn't know about becker.jar. Move becker.jar to /lib/becker.jar, and then Right Click on your Project Folder > Properties > Java Build Path > Libraries Tab > Add Jar > (select your lib/becker.jar). That should resolve your compilation error.

A side note - the reason the error shows up as line 6 is because that is where the main method is (this is what actually is being run when you try to run the application), and when attempting to run the main method it identifies the build error that is really on line 1

guydog28
  • 1,307
  • 1
  • 11
  • 15