Solved

resolving ambiguous references

Posted on 1998-04-21
9
281 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
ID: 1219204
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
ID: 1219205
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
ID: 1219206
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:juris
ID: 1219207
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
 
LVL 5

Expert Comment

by:fontaine
ID: 1219208
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
ID: 1219209
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
ID: 1219210
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
ID: 1219211
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
ID: 1219212
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

726 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