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

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

java - Android Studio Error: class, interface, or enum expeted

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...