mardi 28 juillet 2015

My error says that the table ESTOQUEPRODUTOS was not created, how can i creat?

I don't know why this error is appearing, can somebody help me please? to continue my project? thanks

//BancoDeDados class

package kabashima.materiaisdeconstrucaoconcept.bancodedados;

import android.content.ContentValue`import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import kabashima.materiaisdeconstrucaoconcept.Contact;


public class BancoDeDados extends SQLiteOpenHelper {

//  private static final int DATABASE_VERSION = 1;
//private static final String DATABASE_NAME = "contacts.db";
private static final String TABLE_NAME = "contacts";
private static final String COLUMN_ID = "id";
private static final String COLUMN_NOME = "nome";
private static final String COLUMN_EMAIL = "email";
private static final String COLUMN_SENHA = "senha";
SQLiteDatabase db;

private static final String TABLE_CREATE = "create table contacts(id integer primary key not null  ," +
        "nome text not null, email text not null, senha text not null);";



public BancoDeDados(Context context){

//super(context, DATABASE_NAME, null, DATABASE_VERSION);
super(context, "contacts.db", null, 1);

}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
db.execSQL( ScriptSQL.getCreateEstoqueProdutos());
    this.db=db;
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   String query = "DROP TABLE IF EXISTS" + TABLE_NAME;
    db.execSQL(query);
    this.onCreate(db);
}

public void insertContact(Contact c) {
db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    String query = "select * from contacts";
    Cursor cursor = db.rawQuery(query, null);
    int count = cursor.getCount();

    values.put(COLUMN_ID, count);
    values.put(COLUMN_NOME, c.getNome());
    values.put(COLUMN_EMAIL, c.getEmail());
    values.put(COLUMN_SENHA, c.getSenha());

    db.insert(TABLE_NAME, null, values);
    db.close();


  }
public String searchPass(String nome){
    db = this.getReadableDatabase();
    String query = "select nome, senha from " + TABLE_NAME;
    Cursor cursor = db.rawQuery(query, null);
    String a,b;
    b = "not found";

    if(cursor.moveToFirst()){
        do{
             a = cursor.getString(0);
                if(a.equals(nome))
                {

                b = cursor.getString(1);
                break;

            }
        }while (cursor.moveToNext());

    }
            return b;
}
    }



//AND THE SCRIPTSQL

package kabashima.materiaisdeconstrucaoconcept.bancodedados;


public static String getCreateEstoqueProdutos()
{

    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" CREATE TABLE IF NOT EXISTS ESTOQUEPRODUTOS ( ");
    sqlBuilder.append("_id                INTEGER       NOT NULL ");
    sqlBuilder.append("PRIMARY KEY AUTOINCREMENT, ");
    sqlBuilder.append("NOME               VARCHAR (200), ");
    sqlBuilder.append("MARCA             VARCHAR (200), ");
    sqlBuilder.append("LOJA             VARCHAR (200), ");
    sqlBuilder.append("ESTOQUE         VARCHAR (10), ");
    sqlBuilder.append("VALOR            VARCHAR (30), ");



    sqlBuilder.append(");");

    return sqlBuilder.toString();

}



 }
//RepositorioEstoque class
package kabashima.materiaisdeconstrucaoconcept.bancodedados.dominio;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ArrayAdapter;




public class RepositorioEstoque {
private SQLiteDatabase conn;

public RepositorioEstoque(SQLiteDatabase conn) {
    this.conn = conn;
}

public void TesteInserirProdutos() {

    for (int i = 0; i < 10; i++) {

        ContentValues values = new ContentValues();
        values.put("NOME", "JR");
        conn.insertOrThrow("ESTOQUEPRODUTOS", null, values);



    }

}

    public ArrayAdapter<String> buscaEstoque(Context context)

    {


        ArrayAdapter<String> adpEstoque = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);


        Cursor cursor = conn.query("ESTOQUEPRODUTOS",null,null,null,null,null,null);
        if (cursor.getCount() > 0)
        {
            do {

                cursor.moveToFirst();


                String nome = cursor.getString(1);
                adpEstoque.add(nome);
            } while (cursor.moveToNext());


        }
        return adpEstoque;
    }


}

the error says it on console : 2938- 2938/kabashima.materiaisdeconstrucaoconcept E/SQLiteLog﹕ (1) no such table: ESTOQUEPRODUTOS

Aucun commentaire:

Enregistrer un commentaire