[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: How can I set Eclipse to give me a warning on this error?

www,
Eclipse can only tell you about syntax errors.
The compiler has an option to tell you if you have used a variable and not declared it,


Actually, i just took a second look at your program.
I don't understand how it works in the first place.
You have declared a variable that is local to MyClassA and the tried to use it another class doIt. I don't understand how this works as the local variable is not visible outside of the scope of MyClassA.


The compiler should have given you a variable not defined error.
Ray

www wrote:
Hi,

Several times I have forgotten something like below:

public class MyClassA
{
private MyClassB classB;
private int A, B , C;
public MyClassA()
{
A = 1;
B = 2;
C = 99;


//several times I forgot the following line. To my surprise, I was not warned by Eclipse. It took me a while to find out why my program is not working. How can I set Eclipse to give me a warning.
classB = new ClassB();


    }

    public void doIt()
    {
        classB.method1();
    }

}

Another class

public class Test
{
public static void main(String[] args)
{
MyClassA classA = new MyClassA();
classA.doIt(); //since I forgot to initialize classB inside MyClassA code, this won't work. And it is time consuming for me to find it out.


    }


}