Androidstudio的DWorkplaceDataStoredappsrcmainjavacomapplicationdatastoredSQLiteActivityjava53 错误 不兼容的类型 Cursor无法转换为int cursorRlayoutlinenew int12new StringtitleViewcontentView这个错误怎么解
这个错误是因为在使用SimpleCursorAdapter时,传入的参数类型不正确导致的。SimpleCursorAdapter的最后两个参数应该是一个int数组和一个String数组,分别表示要将数据显示的视图控件的id和从Cursor中取数据的列名。
在你的代码中,你传递了一个int数组new int[]{1,2},这是不正确的。正确的做法是传递一个包含视图控件的id的int数组,例如:new int[]{R.id.titleView, R.id.contentView}。同时,你还需要传递一个String数组,表示从Cursor中取数据的列名,例如:new String[]{"titleView", "contentView"}。
修改后的代码如下:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.line,cursor,
new String[]{"titleView","contentView"},
new int[]{R.id.titleView, R.id.contentView});
这样就能正确地将Cursor中的数据显示在相应的视图控件上了。
原文地址: https://www.cveoy.top/t/topic/i9tg 著作权归作者所有。请勿转载和采集!