gpt4 book ai didi

java - 无法正确返回 arraylist 对象

转载 作者:太空宇宙 更新时间:2023-11-04 14:24:13 25 4
gpt4 key购买 nike

这是我的 Activity 类(class):

package com.blogspot.joyouslybeingjoy.cybpromises;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import java.util.ArrayList;

public class DisplayResult extends Activity {

String selectedCategory;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.verses);

Bundle b = getIntent().getExtras();
String selectedCategory = b.getString("ITEMVALUE");

//Toast.makeText(DisplayResult.this, "Category passed: " + selectedCategory,
// Toast.LENGTH_LONG).show();

final ListView lv = (ListView) findViewById(R.id.listViewItems);
ArrayList<Promise> results = null;
lv.setAdapter(new MyCustomArrayAdapter(this, results));
} // end onCreate

public ArrayList<Promise> GetPromises() {
String table = "promises";
ArrayList<Promise> promises = new ArrayList<Promise>();
Promise prms = new Promise();
SQLiteDatabase newDB;
//SQLiteDatabase db = MyDBHandler.getReadableDatabase();

ArrayList<Promise> results = null;
try {
MyDBHandler dbHandler = new MyDBHandler(this.getApplicationContext());
newDB = dbHandler.getReadableDatabase();
Cursor c = newDB.rawQuery("SELECT * FROM " + MyDBHandler.TABLE_NAME +
" WHERE KEY_CATEGORY = ?", new String[]{selectedCategory});
if (c != null) {
if (c.moveToFirst()) {
do {
String category = c.getString(c.getColumnIndex("KEY_CATEGORY"));
String book = c.getString(c.getColumnIndex("KEY_BOOK"));
String chapter = c.getString(c.getColumnIndex("KEY_CHAPTER"));
String verse = c.getString(c.getColumnIndex("KEY_VERSE"));
String word = c.getString(c.getColumnIndex("KEY_WORD"));
assert results != null;
results.add(category + book + chapter + verse + word);
} while (c.moveToNext());
} // end inner if
} // end outer if
} catch (SQLiteException se) {
Log.e(getClass().getSimpleName(), "Could not create or open the database");
} finally {

}
return results;
}

}

给出错误的行是:

 results.add(category + book + chapter + verse + word);

它说ArrayList中的add不能应用于java.lang.String。好吧,我明白了 - 但我该如何解决它呢?我已经尝试过灯泡的建议。我已经研究过了,教程和其他答案确实使用了这种格式。我能做什么来修复它?谢谢!

最佳答案

结果类型是 Promise,但您将 String 类型添加到列表中。

关于java - 无法正确返回 arraylist 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26845594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com