Java:elementAt(int) is undefined for the type
Résolu
domxaline
Messages postés
204
Statut
Membre
-
domxaline -
domxaline -
Bonjour,
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
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:
- Method is undefined for the type java
- What is my movie français - Télécharger - Divers TV & Vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Downloader for pc - Télécharger - Téléchargement & Transfert
- Eclipse java - Télécharger - Langages
2 réponses
quand j'ecrit comme suivant:
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
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
j'ai résolu mon problème
merci d'avance
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