LogCat errors when Compiling App

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

When i compile the app these errors show:

   sqlite returned: error code = 1, msg = table mensagens already exists    Failure 1 (table mensagens already exists) on 0x240328 when preparing 'create table mensagens(mensagemsalva varchar(250),mensagemenviada varchar(250))'.    sqlite returned: error code = 1, msg = table contatos already exists    Failure 1 (table contatos already exists) on 0x240328 when preparing 'create table contatos(nome varchar(50),telefone varchar(20))'. 

My Main.java has this code which is meant to create the database and its tables:

  onCreate(..){    ...   db = openOrCreateDatabase("banco.db", Context.MODE_WORLD_WRITEABLE, null);     ...     VerificaDados();   }      private void VerificaDados() {     // TODO Auto-generated method stub      try {         //cria uma TABLE de nome MENSAGENS         db.execSQL("create table mensagens(mensagemsalva varchar(250),mensagemenviada varchar(250))");         //ShowMessage("Banco","Criou a tabela de mensagens");     }     catch (Exception e) {          }     try{         //cria uma TABLE de nome CONTATOS         db.execSQL("create table contatos(nome varchar(50),telefone varchar(20))");         //ShowMessage("Banco","Criou a tabela de contatos");     }catch (Exception a){      }  } 

idk what it can be because i just run the app and BAM, errors in LogCat.

回答1:

Have a look athe the SQLiteOpenHelper API Docs.

this class takes care of opening the database if it exists, creating it if it does not, and upgrading it as necessary.

You should try to distinguish between onCreate() and onUpdate().



回答2:

Just Comment (//) the VerificaDados(); because the tables are already created.

onCreate(..){     ...  db = openOrCreateDatabase("banco.db", Context.MODE_WORLD_WRITEABLE, null);     ...    //VerificaDados();    } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!