Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Error !!

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All,
i am using java.AWT.* & java.UTIL.*; packages in my program also i am using "List" class for displaying Names List.
But while compiling the program its showing error as :
Class <<ambiguous>> List not found in java.lang.String.
But if i comment import java.util.*; then its compiling correctly, but program is not working correctly.
Please Suggest.
reply soon
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,
I understand that you are using both "java.awt.List" and "java.util.List" in the same class, correct? If that is the case, then in your code, the java compiler doesn't know which "List" you are referring to if you just write "List". That's why the error message says "ambiguous". You _must_ fully qualify any reference to "List" in your class. In other words, you _must_ write "java.util.List" (when you want to use that one) or "java.awt.List" (when you want to use that one), and not just "List". But you only need to do this (in your example) because you are using two different classes that have the same class name (but different packages).
Hope this answers your question.
Good Luck,
Avi.
 
Piter john
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;
import java.util.List;
import java.io.*;
import java.net.*;
import java.awt.List;
import java.awt.*;
import java.applet.*;
i tried to decleare as above but still it shows error as :
Line 5 : Ambiguous class : java.awt.List and java.util.List
i tried to comment one by one but its not working.
plz suggest !!
Thaks
Piter
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't help if you explicitly import them both! You should only explicitly import the one you use the most. Then for the other you'll have to put the full package and class name whenever you use it.
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Piter,
The compiler gets confused over which List you want. So instead of
List someList = whatever
say java.util.List someList = whatever
or java.awt.List someList = whatever
whichever is the case.
HTH
Ashish H.
 
Piter john
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Thanks for ur suggessions, its really help out.
as i decleared the java.util.list package wherever it requires but about awt package i decleared it at Start only because of compilation problemm
Thanks again. !!
Piter
Another problem is as right now i started working on EJB.I think its quite difficult at start. Can u please suggest me the books and web-links also examples to solve which is easier to understand and deploy
plz suggest !!
 
reply
    Bookmark Topic Watch Topic
  • New Topic