0
My Activity of an Android app has this code.
public class gerenciar2 extends ActionBarActivity{
boolean editar=false, adcionar=false, remover=false;
SQLiteDatabase Banco = null;
Cursor cursor;
String tabbanco="Tabela1";
TextView gerenciar;
ListView lista;
String tabelas[];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gerenciamento);
lista = ( ListView ) findViewById(R.id.list);
abrebanco();
buscardados();
gerelista();
}
public void gerelista() {
cursor.moveToLast();
int x=cursor.getCount();
int y=1;
while(y<x){
//nextdado();
tabelas[x]=retornadado();
dadoanterior();
y++;
};
//return tabelas;
}
public boolean dadoanterior() {
try{
cursor.moveToPrevious();
return true;
}
catch(Exception erro){
return false;
}
}
public boolean buscardados(){
try{
cursor = Banco.query("tabela",
new String [] {"tabelas",}
, null, null, null, null, null);
if (cursor.getCount() != 0){
cursor.moveToFirst();
}else{
String sql = "INSERT INTO tabela (tabelas) " +
"values (Tabela1) ";
Banco.execSQL(sql);
}
return true;
}
catch(Exception erro){
Exibirmensagem("BANCO", "erro ao buscar no banco: "+ erro.getMessage(), "ok");
return false;
}
}
public String retornadado(){
String dado = cursor.getString(cursor.getColumnIndex("tabelas"));
return dado;
}
public void abrebanco(){
try{
Banco = openOrCreateDatabase("banco", MODE_WORLD_WRITEABLE, null);
String sql ="CREATE TABLE IF NOT EXISTS tabela (ID INTEGER PRIMARY KEY" +
", tabelas TEXT)";
Banco.execSQL(sql);
}
catch(Exception erro){
Exibirmensagem("BANCO", "erro ao criar banco: =/"+ erro.getMessage(), "ok");
}
}
The "no intent" error is on this line:
tabelas[x]=retornadado();
If I comment on this line the Activity wheel.
I’m treating the array wrongly?
What the error, You can see in Logcat?
– Cícero Moura
Which error returns? I have no idea what an Intent error is. The variable
tabelas
has any element? It doesn’t look like it. Did I miss something? If you don’t have any element will give error ofindex
or something like that.– Maniero
then accuses error in Intent to call Activity. it does not speak anymore. , does not have any element, I wanted to add
– Joannis
Why don’t you use ORM Lite ? : D http://www.dclick.com.br/2012/05/24/databases-em-android-ormlite-3/
– Cícero Moura