i've an error here , and couldn't solve it :
String generate_card (String Fname , String Lname ,int card_id ){
String cardId = null ;
cardId = Fname.charAt(0) + Fname.charAt(0) + card_id++ ;
return cardId;
}
i've an error here , and couldn't solve it :
String generate_card (String Fname , String Lname ,int card_id ){
String cardId = null ;
cardId = Fname.charAt(0) + Fname.charAt(0) + card_id++ ;
return cardId;
}
I think this is in java,hence the charAt() method
the error here is that you didn't create a new string object,you just assigned it to null
you should have written the following in the second line:
String cardId = "";
Perhaps try
cardId = Character.toString(Fname.charAt(0)) + Character.toString(Fname.charAt(0)) + card_id++;
Java(I assume) can't concatenate two chars and an int.
The problem is that Java won't automatically convert from int to String. This is necessary because you're trying to assing a new value to the String cardId. You could use:
cardId = Fname.charAt(0).toString() + Fname.charAt(0).toString() + Integer.toString(card_id++);
Note: by Java conventions your variable names and parameters shouldn't start with a capital letter
i've found the answer :
String generate_card (String Fname , String Lname ,int card_id ){
String cardId = null ;
cardId = Fname.charAt(0) + Lname.charAt(0) + String.valueOf(card_id++ ) ;
return cardId;
}