TextView 在转换为 String 后返回 java 代码
TextView returning java code after converting to String
我正在尝试从随机数中获取一个字符串,它正在返回这个
Nome1: com.example.OtherActivity@3c9413b0 x com.example.OtherActivity@132c3229:Nome2
Nome1 和 Nome2 的转化率不错,但其余的则不是
我的其他活动class是这个
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 class
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
class toString 方法,因此 returns 字符串不是团队对象:
private class Team {
String str;
public Team(String str) {
this.str = str;
}
@Override
public String toString() {
return str;
}
}
我正在尝试从随机数中获取一个字符串,它正在返回这个
Nome1: com.example.OtherActivity@3c9413b0 x com.example.OtherActivity@132c3229:Nome2
Nome1 和 Nome2 的转化率不错,但其余的则不是
我的其他活动class是这个
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 class
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
class toString 方法,因此 returns 字符串不是团队对象:
private class Team {
String str;
public Team(String str) {
this.str = str;
}
@Override
public String toString() {
return str;
}
}