我的问题是关于Java/Android的:Java/Android:如何使用返回类型'列表<MyType>'?
我创建了一个类MyClass
其中有一个方法getAllData()
返回一个List<MyType> = new ArrayList<MyType>()
。在另一个类MyOtherClass
我打电话给这个方法,并想将返回的列表写入另一个List<MyType>
。
但我得到以下错误:未处理的异常类型异常
我能做些什么呢?
下面的代码:
MyClass.java
public List<MyType> datas = new ArrayList<MyType>();
public List<MyType> getAllData() throws Exception{
//add some things to datas...
return datas;
}
MyOtherClass.java
public void fetchData(){
MyClass mydatas = new MyClass();
List<MyType> thedatas = mydatas.getAllData();
}
我该如何解决这个问题呢? 围绕这个声明的“try/catch(Exception e)”,似乎没有从getAllData();
得到返回的列表感谢很多提前!
你有MyClass和MyOtherClass,但问题是,你有你的类型MyType吗? :D – hovanessyan
是的,当然我有MyType定义。不管怎么说,还是要谢谢你。 @Mark Byers:你到底是什么意思?我无法编译,所以我直接从代码行旁边的代码中直接得到Eclipse的这条消息,在这里我设置了'列表 thedatas = mydatas.getAllData();'。它建议我围绕这个包装一个try/catch块。所以'尝试{列表 thedatas ...} catch(Exception e){}'但这没有帮助。 –
Reymanx