3
I have the following class for bank appointments:
package com.example.tais.books.Dados;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
/**
* Created by Tais on 27/10/2016.
*/
public class EpilogoDado {
private BDHelper sqlite;
private SQLiteDatabase db;
public int total;
public int nt;
public int lv;
public EpilogoDado(Context context){
sqlite = new BDHelper(context);
db = sqlite.getWritableDatabase();
}
public int somarPagina(){
total = 0;
Cursor pag = db.rawQuery("SELECT SUM pagina FROM livro",null);
if (pag.moveToFirst()) {
total = pag.getInt(0);
pag.close();
}
return total;
}
public int contarNota(){
Cursor nota = db.rawQuery("SELECT COUNT * FROM nota", null);
if(nota.moveToFirst()){
nt = nota.getCount();
nota.close();
}
return nt;
}
public int contarLivro(){
Cursor livro = db.rawQuery("SELECT COUNT * FROM livro", null);
if (livro.moveToFirst()){
lv = livro.getCount();
livro.close();
}
return lv;
}
}
And this to display the results of the queries:
package com.example.tais.books;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.example.tais.books.Dados.EpilogoDado;
public class epilogoBook extends AppCompatActivity {
EpilogoDado bd;
TextView paginometro;
TextView notast;
TextView livrot;
TextView ntplv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_epilogo_book);
bd = new EpilogoDado(getApplicationContext());
paginometro = (TextView)findViewById(R.id.TextViewPg);
livrot = (TextView)findViewById(R.id.TextViewLv);
notast = (TextView)findViewById(R.id.TextViewNt);
ntplv = (TextView)findViewById(R.id.TextViewNpL);
paginometro.setText(Integer.parseInt(String.valueOf(bd.somarPagina())));
livrot.setText(Integer.parseInt(String.valueOf(bd.contarLivro())));
notast.setText(Integer.parseInt(String.valueOf(bd.contarNota())));
ntplv.setText(Integer.parseInt(String.valueOf(bd.contarNota()/bd.contarLivro())));
}
}
And it’s giving error when I run, the application for execution.
By Debug I find that class values EpilogoDado
is null
.
There is data registered in the database.
Grateful!
Hello @Tais Caires, welcome to Stack Overflow! You could attach the logcat with the error along with your question?
– regmoraes
saveInstadedState = null - bd = null - paginometro = null - too Textview = null @regmoraes
– Tais Caires
Epilogodado.java:30 epilogoBook.java:32
– Tais Caires
actually it would be better to copy and paste the logcat directly into the question by editing it.
– regmoraes