no such table: tbcarro


Following some examples, I'm in doubt about the following error:

11-24 20:49:14.803 18215-18215/tiburski.rg.cadastrocarro E/SQLiteDatabase: Error inserting nome=ggggg modelo=ggggg placa=hhhh
android.database.sqlite.SQLiteException: no such table: tbcarro (code 1): , while compiling: INSERT INTO tbcarro(nome,modelo,placa) VALUES (?,?,?)
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(
    at android.database.sqlite.SQLiteConnection.prepare(
    at android.database.sqlite.SQLiteSession.prepare(
    at android.database.sqlite.SQLiteProgram.(
    at android.database.sqlite.SQLiteStatement.(
    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(
    at android.database.sqlite.SQLiteDatabase.insert(

According to some examples already created, they follow the classes responsible for the database.

public class DataModal {

    private static final String DB_NOME = "carro.db";
    private static final int DB_VERSAO = 4;

    private static final String TBL_CARRO = "tbcarro";
    private static final String COLUNA_ID = "_id";
    private static final String COLUNA_NOME = "nome";
    private static final String COLUNA_PLACA = "placa";
    private static final String COLUNA_MODELO = "modelo";


    public static String criarTabela() {
        String CREATE_TABLE = " CREATE TABLE IF NOT EXISTS "+ getTblCarro() +" ( "
                + getColunaId() +" INTEGER PRIMARY KEY AUTOINCREMENT, "
                + getColunaNome() +" VARCHAR NOT NULL, "
                + getColunaPlaca() +" VARCHAR UNSIGNED NULL, "
                + getColunaModelo() +" VARCHAR UNSIGNED NULL ); ";
        return CREATE_TABLE;

    public static String getDbNome() {
        return DB_NOME;

    public static int getDbVersao() {
        return DB_VERSAO;

    public static String getTblCarro() {
        return TBL_CARRO;

    public static String getColunaId() {
        return COLUNA_ID;

    public static String getColunaNome() {
        return COLUNA_NOME;

    public static String getColunaPlaca() {
        return COLUNA_PLACA;

    public static String getColunaModelo() {
        return COLUNA_MODELO;
public class DataSource extends SQLiteOpenHelper {

    private SQLiteDatabase mDb;

    public DataSource(Context context) {
        super(context, DataModal.getDbNome(), null, DataModal.getDbVersao());
        mDb = this.getReadableDatabase();

    public void onCreate(SQLiteDatabase sqLiteDatabase) {

    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

Other examples with basically similar code work correctly. However, in this example the mentioned error is occurring. Could you point me to where the fault is or the faults in the code?

One more important point is that in this example, in the persistence class, I inserted a new method, which I had not used until then.

private Context mContext;
    private static Persistencia mInstance;
    private static SQLiteDatabase mDb;

    public static Persistencia getmInstance(Context context) {
        if (mInstance == null) {
            synchronized (Persistencia.class) {
                if (mInstance == null) {
                    mInstance = new Persistencia(context);
                    mDb = context.openOrCreateDatabase(DataModal.getDbNome(), Context.MODE_PRIVATE, null);
        return mInstance;

    private Persistencia(Context context) {
        this.mContext = context;
asked by anonymous 25.11.2016 / 00:05

1 answer


by the link beside - > link the error is as follows:

There is an old version of the database on your device that makes the app feel that the database does not exist. if so, the solution is to uninstall and reinstall the database from scratch.

25.11.2016 / 01:27