Solved

resolving ambiguous references

Posted on 1998-04-21
9
278 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

829 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