Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法从databasehandler Java中获取字符串 嗨,我正试图从我的数据库处理程序中获取字符串。我没有得到任何错误,我得到的id是这样的字符串*_Java_Arrays_Database - Fatal编程技术网

我无法从databasehandler Java中获取字符串 嗨,我正试图从我的数据库处理程序中获取字符串。我没有得到任何错误,我得到的id是这样的字符串*

我无法从databasehandler Java中获取字符串 嗨,我正试图从我的数据库处理程序中获取字符串。我没有得到任何错误,我得到的id是这样的字符串*,java,arrays,database,Java,Arrays,Database,com.example.drinkingtime.Treburi。NumeBazaDeDate@752fc40 有什么需要帮忙的吗?我是编程初学者 public void test(){ ArrayList<String> a=new ArrayList<>(); a.add("ana are mere"); a.add("ana are mere");

com.example.drinkingtime.Treburi。NumeBazaDeDate@752fc40

有什么需要帮忙的吗?我是编程初学者

 public void test(){
            ArrayList<String> a=new ArrayList<>();
            a.add("ana are mere");
            a.add("ana are mere");
            a.add("ana are mere");
                DataBaseHandler db=new DataBaseHandler(this);
                String y=db.getNume(2).toString();
                String z=a.get(0).replace("mere",y);
                intrebari.setText(z);
                Log.d("hi", "HI "+y);
       }
在这一行

String y=db.getNume(2.toString();
调用toString方法将对象转换为字符串。默认情况下,此方法返回与@连接的完整类名和对象地址

您应该重写该方法,以便它返回您想要的内容。字段值,例如,与连接

比如说,如果NumeBazaDeDate有name字段,并且希望y变量包含name表单db,那么toString方法应该是这样的

公共字符串toString(){
返回名称;
}

我应该怎么做?我使用ctrl+o来获得它,但我应该在那里写些什么?更新了我的答案。现在更清楚了吗?试试
String y=db.getNume(2.getNume()成功了,谢谢各位。你太棒了。是的,这是逻辑,我得到一个完整的对象,然后我需要得到一个名字yess。谢谢
public class DataBaseHandler extends SQLiteOpenHelper {
    private final Context context;

    public DataBaseHandler(@Nullable Context context) {
        super(context, Util.DATABASE_NAME, null, Util.DATABASE_VERSION);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACT_TABLE = "CREATE TABLE " + Util.TABLE_NAME + "("
                + Util.KEY_ID + " INTEGER PRIMARY KEY," + Util.KEY_NAME + " TEXT" + ")";
        db.execSQL(CREATE_CONTACT_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + Util.TABLE_NAME);

        //create a table again
        onCreate(db);
    }

    public void addName(NumeBazaDeDate numeBazaDeDate) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(Util.KEY_NAME, numeBazaDeDate.getNume());

        db.insert(Util.TABLE_NAME, null, values);
    }

    public NumeBazaDeDate getNume(int id) {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.query(Util.TABLE_NAME, new String[]{Util.KEY_ID, Util.KEY_NAME},
                Util.KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();
        NumeBazaDeDate numeBazaDeDate = new NumeBazaDeDate();
        numeBazaDeDate.setId(Integer.parseInt(cursor.getString(0)));
        numeBazaDeDate.setNume(cursor.getString(1));

        return numeBazaDeDate;
    }

}