我正在尝试将适配器添加到我的活动中,以便显示动物列表。
我收到此错误:
11-24 12:08:20.918: E/AndroidRuntime(6394): java.lang.ClassCastException: com.myapp.animals.Animal cannot be cast to java.util.Map
package com.myapp.animals;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class SlachtList extends Activity {
static final String[] FROM = {AnimalData.C_BATCHNR, AnimalData.C_VOLGNUMMER};
static final int[] TO = {android.R.id.text1,android.R.id.text2 };
ListView list;
List animals;
SimpleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slacht_list);
list = (ListView) findViewById(R.id.list);
animals = ((AnimalApp) getApplication()).animalData.getAnimals();
adapter = new SimpleAdapter(this, animals, android.R.layout.two_line_list_item, FROM, TO);
list.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_slacht_list, menu);
return true;
}
}
动物是动物对象的列表。显然适配器想要不同类型的对象。我认为这就是问题所在。谁能帮我解决这个问题?