Sachin Mhetre
Sachin Mhetre

Reputation: 4543

Different behaviour of netbeans and console

I have written a code in java. In which I have created a package called xml-creator.
Package xml_creator has 3 classes say XML_Control, XML_Creator, and XML_implement.

When I run my project on netbeans (NetBeans 7.0) it works fine. But if I try to compile code on console, I get various errors like

When I compiled XML_Creator.java, I get following errors.

XML_Creator.java:371: cannot find symbol
symbol  : variable XML_implement
location: class xml_creator.XML_Creator
                    typeAttr.setValue(XML_implement.table_col[i][2]);
                                      ^
XML_Creator.java:375: cannot find symbol
symbol  : variable XML_implement
location: class xml_creator.XML_Creator
                for(int j=0;j<XML_implement.kTab;j++)
                              ^


XML_Creator and XML_implemenr both are in same package but non of them extend each other.

I am sorry I cant show code on this site as it is too large and aginst the company's policies.

I dont understand why it is showing me errors?

Sample code
XML_Control.java

package xml_creator;
public class XML_Control 
{
    public static void main(String as[])
    {
        XML_Creator xml = new XML_Creator();    
    }
}

XML_Creator.java

package xml-creator;

public class XML_Creator
{
    XML_implement ixml = new XML_implement();
    public XML_Creator() 
    {
        System.out.println(""+ixml.a);
    }
}

XML_implement.java

package xml_creator;
public class XML_implement 
{
    public int a;
    public XML_implement()
    {
        a = 10;
    }
}

So when I compile XML_Creator.java, console gives error.

Upvotes: 1

Views: 112

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500225

It sounds like you're compiling within the directory containing the .java file, and only telling the compiler about one of the source files. That's the problem - to try to find a source or class file, the compiler is using the package name, and expecting the packages to be laid out in the conventional fashion. Compile from the root of the source tree - which I certainly hope you're using - like this:

javac xml_creator/*.java

You may also want to specify an output directory - which again will be the root of the directory hierarchy for packages:

javac -d bin xml_creator/*.java

If you're building regularly from the command-line (and not just for throwaway code) you should look into using a build system such as Ant.

Upvotes: 4

Related Questions