我有一个应用程序将名称和图像存储在数据库中。然后我在listview上打印图像的名称。但我只能看到数据库中的前三个元素。它显示我是完全错误的窗口。数据库没有问题,我查了一下数据库通过sqlitebrowser并且那里存在所有元素。可能我的arrayadapter有问题。什么问题?图像小30kb。 我尝试在ListView上查看所有图像时出错
错误
W/CursorWindow: Window is full: requested allocation 5397663 bytes, free space 1143664 bytes, window size 2097152 bytes
W/CursorWindow: Window is full: requested allocation 5397663 bytes, free space 2023760 bytes, window size 2097152 bytes
Window is full: requested allocation 5397663 bytes, free space 2096700 bytes, window size 2097152 bytes
E/SQLiteCursor: onMove() return false. RequiredPos: 3 WindowStartPos: 3 WindowRowCount: 0(original count of query: 6)
OnCreate方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listView);
final ArrayList artName = new ArrayList();
artImage = new ArrayList();
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,artName);
listView.setAdapter(arrayAdapter);
try {
Main2Activity.database = this.openOrCreateDatabase("Arts", MODE_PRIVATE, null);
Main2Activity.database.execSQL("CREATE TABLE IF NOT EXISTS arts (name VARCHAR, image BLOB)");
Cursor cursor = Main2Activity.database.rawQuery("SELECT * FROM arts", null);//cursor is for data recieving
int nameIx = cursor.getColumnIndex("name");
int imageIx = cursor.getColumnIndex("image");
cursor.moveToFirst();
while (cursor != null) {
artName.add(cursor.getString(nameIx));
//adding bitmap into artImage
byte[] byteArray = cursor.getBlob(imageIx);
//decoding bitmaps
Bitmap image = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);
artImage.add(image);
cursor.moveToNext();
arrayAdapter.notifyDataSetChanged();//data degistiyse arrayadapter'a haber veriyor ve guncelleyip kullaniciya gosterir
}
} catch (Exception e) {
e.printStackTrace();
}
//selecting saved images
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra("info", "old");
intent.putExtra("name", artName.get(position));
intent.putExtra("position", position);
startActivity(intent);
}
});
}
}
来自xml的ListView
android:id="@+id/listView"
android:layout_width="368dp"
android:layout_height="495dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />