Solved

resolving ambiguous references

Posted on 1998-04-21
9
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

623 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