下面是使用databasehelper类从数据库检索数据的代码 public List<Hospitals> getHospitals(Context context){ Hospitals hospitals = null; List<Hospitals> hospitalList = new ArrayList<>(); openDatabase(context); Cursor cursor = database.rawQuery("SELECT * FROM buildings WHERE category_id = 1", null); cursor.moveToFirst(); while(!cursor.isAfterLast()){ hospitals = new Hospitals(cursor.getInt(0), cursor.getString(1), cursor.getFloat(2), cursor.getFloat(4)); hospitalList.add(hospitals); cursor.moveToNext(); } cursor.close(); closeDatabase(); return hospitalList;}这是我的班级医院public class Hospitals {private int id;private String name;private Float latitude;private Float longhitude;public Hospitals(int id, String name, Float latitude, Float longhitude ){ this.id = id; this.name = name; this.latitude = latitude; this.longhitude = longhitude;}public int getId() { return id;}public void setId(int id) { this.id = id;}public String getName() { return name;}public void setName(String name) { this.name = name;}public Float getLatitude() { return latitude;}public void setLatitude(Float latitude) { this.latitude = latitude;}public Float getLonghitude() { return longhitude;}public void setLonghitude(Float longhitude) { this.longhitude = longhitude;}}下面是我在main activity中的代码,它将list传递给fragmentList<Hospitals> result = databaseHelper.getHospitals(this); Bundle bundle = new Bundle(); bundle.putParcelableArrayList("valuesArray", result); GmapFragment gmapFragment = new GmapFragment(); gmapFragment.setArguments(bundle); fragmentManager.beginTransaction().replace(R.id.mainLayout, gmapFragment).commit();我在putparcelablearraylist()中得到了第二个参数-错误的第二个参数类型。找到:“java.util.List”,必需:“java.util.ArrayList”如何解决这个错误? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 第二个参数类型错误。找到:“java.util.list”,必需:'java.util.arraylist的首先将列表转换为arraylist。 List<Hospitals> result = databaseHelper.getHospitals(this); ArrayList<Hospitals> al_HOSPITAL = new ArrayList<>(result.size()); al_HOSPITAL.addAll(result);那么Bundle bundle = new Bundle();bundle.putSerializable("valuesArray", al_HOSPITAL);你应该使用Parcelable。使用Parcelable比Serializable更好。Parcelable是time-consuming and error-prone process。其实例可以写入和还原的类的接口从包裹里。实现Parcelable接口的类也必须有一个名为creator的非空静态字段,该字段的类型实现了parcelable.creator接口。public class Hospitals implements Parcelable {最后Clean-Rebuild-Run。希望这有帮助。 (adsbygoogle = window.adsbygoogle || []).push({}); 07-25 23:46