loops - Incompatible types: Card cannot be converted to java.lang.String -


i keep getting error code. can't seem find problem.

i'm not sure because looked in text book , gives me similar method except different variables.

i'm on bluej.

 public int findfirstofplayer(string searchstring) {     int index = 0;     boolean searching = true;     while(index < cards.size() && searching) {         string cardname = cards.get(index); // error highlights index         if(cardname.contains(searchstring)) {             searching = false;         }         else {             index++;         }         if(searching) {             return -1;         }         else {             return index;         }     } } 

here problem, , if used eclipse or idea, highlight you.

    string cardname = cards.get(index); 

obviously, cards not compatible string, can't assign way, because collection card not of type string aka arraylist<string> cards can either:

    string cardname = cards.get(index).tostring(); 

or

    string cardname = string.valueof(cards.get(index)); 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -