Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error #: 361 : variable required, but value found

 
Rashid Hafeez Khokhar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if we have the inPut={"A","B","A","C","B"} then we want the non-repeated array with element as outPut={"A","B","C"}

The following code showing the "Error #: 361 : variable required, but value found at line 12, column 34".

Vector inPut=new Vector();
Vector outPut=new Vector();
int m=0;
for(int i=0; i < inPut.size(); i++){

if(inPut.elementAt(i) == null) continue;
else{

for(int j=i+1; j < inPut.size(); j++){

if(inPut.elementAt(i) == inPut.elementAt(j))

// Error Line=12 inPut.elementAt(i) = null;

} // inner for
} // else
outPut.elementAt(m) = inPut.elementAt(i);
System.out.println("OutPut=" +outPut.elementAt(m));
m++;
} // outer for


Kind Regards

Rashid.
rhkhokhar@hotmail.com
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector implements List I thikn you are doing a lot of work you don't have to. List (and thus vector) has a contains method which will tell you if the vector already contains what you have). for instance if (!output.contains(element)) //add it here

Regarding the original question i'm not sure what to tell you, except you may want to add some code formatting tags to make it easier to read
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of things here
1) inPut.elementAt(i) gives you an object that you can't set equal to seomthing if you want to set the value of an object at a particular position in the array do a vector.setElementAt(index, object);

2) The second for loop is not necessary to see if the vector contains the object you are looking for it's easy enough to say outPut.contains(inPut.elementAt(i));

3) The M is not required either as you should be able to just say outPut.add(object) - unless of course you have to maintain the same "number" position in the array for some reason

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic