我试图从一个随机数中得到一个字符串,它返回这个
Nome1:com.example.OtherActivity@3c9413b0 x com.example.OtherActivity@132c3229:Nome2
Nome1和Nome2转换良好,但其余部分却没有
我的OtherActivity课程是这个
public class OtherActivity{
private String teamOne;
public Team(String teamOne) {
this.teamOne = teamOne;
}
public String getTeamOne() {
return teamOne;
}
public void setTeamOne(String teamOne) {
this.teamOne = teamOne;
}
}
我的TeamMixer班
public class TeamMixer extends PlayerNames {
public ArrayList<Team> times = null;
public TeamMixer(ArrayList<Team> times) {
this.times = times;
}
protected String tellJoke(){
Double randomNumber = new Double(Math.random() * times.size());
Double randomNumber1 = new Double(Math.random() * times.size());
int randomNum1 = randomNumber1.intValue();
int randomNum = randomNumber.intValue();
Team time2 = times.get(randomNum);
Team time3 = times.get(randomNum1);
String timeString = String.valueOf(time3);
String timeString2 = time2.toString();
if(time2 == time3){
Double randomNumber2 = new Double(Math.random() * times.size());
int randomNum2 = randomNumber2.intValue();
Team time4 = times.get(randomNum2);
String timeString3 = String.valueOf(time4);
String tentativa = sayTeam(timeString2, timeString3);
return tentativa;
} else{
String tentativa2 = sayTeam(timeString, timeString2);
return tentativa2;
}
}
protected String sayTeam(String teams, String teams2){
String message = (getNamePlayerOne()+": " + teams + " x " + teams2 + " :" + getNamePlayerTwo());
return message;
}
}
感谢帮助!
最佳答案
覆盖您的Team
类toString方法,因此它返回字符串而不是Team对象:
private class Team {
String str;
public Team(String str) {
this.str = str;
}
@Override
public String toString() {
return str;
}
}