Java:elementAt(int) is undefined for the type

Résolu/Fermé
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 - 27 juin 2012 à 17:27
 domxaline - 28 juin 2012 à 11:01
Bonjour,
import java.util.Vector;
public class DupValue 
{
	public static void main(String[]args)
	{
		String tmpVector;
		Vector  v=new Vector();
		v.add("Delhi");
		v.add("Mumbai");
		v.add("Calcutta");
		v.add("Chennai");
		v.add("Delhi");
		Vector tempVector=new Vector();
		String tmpValue;
		for(int j=0; j<=v.size();j++)
		{
			tmpValue=(String)v.elementAt(j);
			if(tmpValue!=null)
			{
				if(tmpVector.isEmpty())
					tmpVector.addElement(tmpValue);
				if (tmpVector.indexOf(tmpValue==-1))
					tmpVector.addElement(tmpValue);
			}
		}
		for(int j=0; j<tmpVector.size(); j++)
		{
			System.out.print(tmpVector.elementAt(j));
		}
	}
}


en compilant mon prg,ce dernier m'afficher une erreur de message
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addElement(String) is undefined for the type String
Incompatible operand types String and int
The method addElement(String) is undefined for the type String
The method size() is undefined for the type String
The method elementAt(int) is undefined for the type String

at DupValue.main(DupValue.java:21)

la ligne 21 est
tmpVector.addElement(tmpValue);

aidez moi svp
A voir également:

2 réponses

domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 10
Modifié par domxaline le 27/06/2012 à 18:13
quand j'ecrit comme suivant:
for(int j=0; j<=v.size();j++) 
  { 
   tmpValue=(String)v.elementAt(j); 
   if(tmpValue!=null) 
   { 
    if(tmpVector.isEmpty())     
     tmpVector.addElement(tmpValue); 

    if (tmpVector.indexOf(tmpValue==-1)) 
     tmpVector.addElement(tmpValue); 
   } 
  } 
  for(int j=0; j<tmpVector.size(); j++) 
  { 
   System.out.print(tmpVector.elementAt(j)); 
  } 

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addElement(String) is undefined for the type String
Incompatible operand types String and int
The method addElement(String) is undefined for the type String
The method size() is undefined for the type String
The method elementAt(int) is undefined for the type String

at DupValue.main(DupValue.java:21)


la ligne 21 est
tmpVector(int).addElement(tmpValue);


aidez moi svp
1
j'ai résolu mon problème
import java.util.Vector;
public class DupValue 
{
	public static void main(String[]args)
	{
		Vector  v=new Vector();
		v.add("Delhi");
		v.add("Mumbai");
		v.add("Calcutta");
		v.add("Chennai");
		v.add("Delhi");
		Vector tmpVector=new Vector();
		String tmpValue;
		for(int j=0; j<v.size();j++)
		{
			tmpValue=(String)v.elementAt(j);
			if(tmpValue!=null)
			{
				if(tmpVector.isEmpty())
				{
					tmpVector.addElement(tmpValue);
				}
				if (tmpVector.indexOf(tmpValue)==-1)
				{
					tmpVector.addElement(tmpValue);
				}
			}
		}
		for(int j=0; j<tmpVector.size(); j++)
		{
			System.out.print(tmpVector.elementAt(j)+",");
		}
	}
}


merci d'avance
0