• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error !!

 
Piter john
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • 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
  • 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 !!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!