由于某种原因,当我运行我的应用程序时,而不是获取演讲的名称,我得到一串随机显示的字符。我不知道为什么。提前致谢!toString方法返回随机字符
public Lecture(String lecturename) {
this.lecturename = lecturename;
listofwork = new ArrayList<Work>();
}
public String toString(Lecture lecture) {
return lecture.lecturename;
}
/////////// IN ANOTHER ACTIVITY /////////////////////
Lecture test = new Lecture("TEST");
Toast.makeText(getApplicationContext(), test.toString(), Toast.LENGTH_LONG).show();
而不是举杯说“测试”,我得到[email protected]。我有一种感觉,它返回的是实际的演讲对象而不是字符串。但是,我找不到为什么导致代码非常简单。
看到从THR Object类继承了toString()方法的代码。 –
另请注意,您正在重载toString方法。 –
尝试[this](http://stackoverflow.com/questions/3615721/how-to-use-the-tostring-method-in-java) – Geros