views:

126

answers:

3
package package.b;
class ClassB {

public ClassB(BaseClass bc, XMLBase obj1) { }
}


import package.b.ClassB;

class A extends BaseClass {

    public void function() {
        TestXML obj1 = new TestXML();

        ClassB bObj = new ClassB(this, obj1);
    }

}


When I compile the above code, I get an error "cannot find symbol symbol : constructor ClassB(ClassA, Object1)"

But when I pass "null" for both arguments, it compiles fine.

Why so?

Can anyone help me?

TIA

+1  A: 

This should compile unless there are other errors e.g. TestXML is not a valid class or does not extend XMLBase which you say it does. Without the complete class defn it cannot be helped.

fastcodejava
+2  A: 

Both classes are in different packages and have the (default) package visibility, hence they can't see each other. Make B public and it should be fine:

public class ClassB {
    //blabla
}
Jerome
I suspect that's not the problem, as otherwise it wouldn't compile when "null" was used for both arguments. Note that class A *doesn't* have to be public anyway - ClassB doesn't directly refer to it, so it doesn't matter.
Jon Skeet
you're right for A, editing.
Jerome
And for class B, how do you explain the constructor with two null arguments working unless in reality it's public already?
Jon Skeet
+3  A: 

Your error message doesn't match the constructor call you've shown. You've got:

// In the code
public ClassB(BaseClass bc, XMLBase obj1)

// In the error message
ClassB(ClassA, Object1)

What is Object1, what's XMLBase, and what's TestXML?

Additionally there's the invalid package name as Vinegar pointed out. If you could produce a short but complete example which is failing, that would help. At the moment it looks like you're using cut down versions of a few classes but naming them inconsistently, which makes it much harder to work out what's going on.

Also, is ClassB public? It's not in your sample code, but you're importing it which presumably means it's in a different package... that won't work, as the default access is restricted to code in the same package. Given your comment about it working if you pass in nulls, I suspect it is public (or the import is irrelevant) - again, a complete example would really help.

Jon Skeet