Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to do an insert test data in my database, but is not working.

Follow this video as a reference, but it did not work: https://www.youtube.com/watch?v=RPi7ueKwEXg

See below:

package com.bytemeta.bytenota.dominio;

import android.content.ContentValues;
import android.content.Context;
import android.database.*;
import android.database.sqlite.*;
import android.widget.ArrayAdapter;
import android.widget.*;

public class RepositorioCadastro{
    private SQLiteDatabase conn;
    public RepositorioCadastro(SQLiteDatabase conn){
        this.conn = conn;
    }
        public void testeInserirCadastro(){
            for (int i = 0; i < 10; i++){
                ContentValues values = new ContentValues();
                values.put("NOME", "THIAGO");
                conn.insertOrThrow("CADASTRO", null, values);
            }
        }
    }

    public ArrayAdapter<String> buscaCadastro(Context context){

        ArrayAdapter<String> adpCadastro = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
        Cursor cursor = conn.query("BYTENOTA_DB",null,null,null,null,null,null,null);

        if (cursor.getCount() > 0) {

            cursor.moveToFirst();
            do {
                String NOME = cursor.getString(1);
                adpCadastro.add(NOME);
            }while (cursor.moveToNext());
        }
        return adpCadastro;

    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
267 views
Welcome To Ask or Share your Answers For Others

1 Answer

Android Studio throws that error when you have code out of the class declaration. Your public ArrayAdapter<String> buscaCadastro is out of the class right now. Remove the extra closing curly brace after testeInserirCadastro, that should fix it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...