My problem is about Java / Android :
I created a class MyClass which has a method getAllData() that returns an List<MyType> = new ArrayList<MyType>(). In an other class MyOtherClass I call to this method and want to write the returned List into another List<MyType>.
But I get the following error: Unhandled exception type Exception
What can I do about this?
Here’s the code:
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();
}
How can I solve the problem?
With an “try / catch(Exception e)” surrounding the statement, it seems not to get the returned List from getAllData();
Thanks a lot in advance!
Since
getAllData()might throws a checked exception (i.e., an exception that is not aRunTimeException), you have to surround the statement withtry-catchOr add
throwsclause after the method name.