Solved

resolving ambiguous references

Posted on 1998-04-21
9
263 Views
Last Modified: 2012-05-04
I have the following:

class A extends C implements N in package root.serv.adm, the file imports root.* and root.serv.*;

interface N in package root;

class C in package root.serv;

When compiling I get a "reference to C is ambiguous; both class root.serv.C in package root.serv and class root.A in package root match." error.

There definately is no C class in package root, neither compiled nor as a .java file.

And what I want to do least is specify full package namespace when defining A like in
class A extends root.serv.C implements N;

If I drop the import root.*; clause I get a N not found error;
If I drop the import root.serv.*; clause I get a root.C is not public in package root error.

Any ideas?

What could I be missing?
0
Comment
Question by:juris
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:fontaine
Comment Utility
A general rule is that only public classes and interfaces in other packages can be accessed.
So, C *has* to be public, as well as N. I have reproduced your example and produced some sample code. I post you it here, so that you can solve  your problem by analogy.

The main directory contains:  A.java & root (directory).
"root" contains: N.java & serv (directory)
"serv" contains C.java & adm (directort)
"adm" contains A.java

Code for A.java
----------------------

package root.serv.adm;

import root.*;
import root.serv.*;

class A extends C implements N
{
 public A() {}
 public int n() { return 1; } // interface...
}

Code for C.java
----------------------

package root.serv;

public class C
{

 public C()
 {
 }

}

Code for N.java
---------------------

package root;

public interface N
{
 public int n();
}





0
 

Expert Comment

by:java_lord
Comment Utility
Java_Lord Lord LOgin Procedure Begin:
tar -cvf tar.xwindows.unix.root.servPack__number
ASN data encoding please wait....

You must change your CLASSPATH dear. I told you.

ASN data received. Login complete.

Dear I told again.


0
 

Expert Comment

by:java_lord
Comment Utility
Dear I told again.

 
 
 
   
 

Here are your options, java_lord:


Have a comment to juris?
 

 
 Check here if you'd like an email notification whenever this question is updated



(Or you can always... Return to Java Programming topic area)  
 
   
 



--------------------------------------------------------------------------------
Copyrights © 1996-
0
 

Author Comment

by:juris
Comment Utility
No, everything is already public.

root.C is not public in package root error is ridiculous because there is no root.C, C is in root.serv.C!

I'm using JBuilder BTW.

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Expert Comment

by:fontaine
Comment Utility
You have not followed point by point my explanation. From my previous answer:

[snip]
>"root" contains: N.java & serv (directory)
>"serv" contains C.java & adm (directort)
[snip]
>Code for C.java
> ----------------------
>
>package root.serv;
>
>public class C
>{
>
>  public C()
>  {
>   }
>
>  }

So, as you say: "C is in root.serv.C!". That's exactly what I wrote. The IDE you use has nothing to do with your problem. Try the code I give (this time). It has been tested...
0
 

Author Comment

by:juris
Comment Utility
Yeah, fontaine, your code works, but the one I have written already does not!!!

I mean, I wasn't writing classes A and C, it was a lot of code and it doesn't work although everything is the way that code is.

I don't know what's the problem.

0
 
LVL 5

Expert Comment

by:fontaine
Comment Utility
I know that your problem is more complex. I do with what I have (your example with A, C and N). The idea is to use the code I posted as an example of valid structure. Replace A, C and N by the class names that cause you problems. If you see that they are not located at the same place as in the example, move them. If this is correct, check the "package" and "import" lines. Verify also if they are public or not. Tell me about this.
0
 

Accepted Solution

by:
ambrosio earned 200 total points
Comment Utility
Juris,

check what you have in your JBuilder\myclasses\ folder? If you have moved your source files to different packages not using JBuilder the previously compiled .class files can still be in JBuilder\myclasses folder in wrong places and can confuse the compiler.

0
 

Author Comment

by:juris
Comment Utility
Oh, yeah, Ambrosio, I just moved my classes into multiple packages from one and JBuilder\myclasses\ was full of cached .class files.

Thanks, for your help, everyone.

fountaine, thanks a lot!

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now