当我启动程序时,它会给我一个对象的链接,而我想获取内容。哪里是我的错?
我认为问题在于storage.addRecord(record)
中的ReaderXls.class
。
结果:
Reading is over
Start reading from Storage
work2obj.Record@2910d926
。
public class Start {
public static void main(String[] args) {
System.out.println("Start reading from Xls");
ReaderXls read = new ReaderXls();
Storage storage;
storage = read.ReadXls("Text1obj",0,1);
System.out.println("Reading is over");
System.out.println("Start reading from Storage");
System.out.println(storage.getRecord(1));
}
}
public class Storage
{
List<Record> record;
public Storage(){
this.record = new ArrayList<Record>();
}
public Record getRecord(int number){
return this.record.get(number);
}
}
public class ReaderXls {
public Storage ReadXls(String sfilename,int firstColumn, int lastColumn){
Storage storage = new Storage();
try {
Record record = new Record(j, Integer.parseInt(ContentCount), RowContent);
storage.addRecord(record);
}
}
答案 0 :(得分:7)
您应该在toString
类中实现Record
方法,以返回包含您要显示的数据的字符串。
默认情况下,由于您的类未实现toString
,因此会调用Object.toString()
,这将返回<the name of the class>@<the object's hashcode>
答案 1 :(得分:4)