Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

resolving ambiguous references

Posted on 1998-04-21
9
Medium Priority
?
296 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

730 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