下面的代码从服务器获取数据,但不能转换为列表
此代码显示错误java.util.HashMap无法强制转换为com.tesla.developer.teslatvinverters.BackendlessClasses.InvertersData
相同的代码适用于其他后端类
Backendless.Data.of(InvertersData.class).find(new AsyncCallback<BackendlessCollection<InvertersData>>() {
@Override
public void handleResponse(BackendlessCollection<InvertersData> inverterData) {
// all Contact instances have been found
// error is in the Toast when i try to get id of object , but it gives the size of data accurate
List<InvertersData> allData = inverterData.getData();
Toast.makeText(MainActivity.this, "" +allData.get(0).getObjectId(),Toast.LENGTH_SHORT).show();
// iterate over the received objects
Iterator<InvertersData> iterator = allData.iterator();
while( iterator.hasNext())
{
Log.e("Object :", ""+iterator.next().getObjectId());
}
}
});
答案 0 :(得分:0)
您需要明确告诉Backendless如何将HashMap强制转换为类。
在app init期间放置它。
Backendless.Persistence.mapTableToClass( "InvertersData", InvertersData.class );