2
My activity
with the database is with some problem, because I created the class
right and Android Studio is not showing any error, but when I will run it on mobile when opening activity
that has the database it closes.
Would anyone have any idea what it is?
package Bancosimples (bank)
Simplesbanco
package BancoSimples;
import com.allsport.miyonic.allsport.SimplesHome;
import java.io.Serializable;
public class SimplesBanco implements Serializable{
public long id;
public String timeum;
public String timedois;
public String golone;
public String goldois;
public SimplesBanco(long id, String timeum, String timedois, String golone, String goldois){
this.id = id;
this.timeum = timeum;
this.timedois = timedois;
this.golone = golone;
this.goldois = goldois;
}
@Override
public String toString() {
return timeum;
}
}
Simplesrepositorio
package BancoSimples;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
public class SimplesRepositorio {
private SimplesSQLHelper helper;
public SimplesRepositorio(Context ctx) {
helper = new SimplesSQLHelper(ctx);
}
private long inserir(SimplesBanco simplao) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(SimplesSQLHelper.COLUNA_NOMEONE, simplao.timeum);
cv.put(SimplesSQLHelper.COLUNA_NOMETWO, simplao.timedois);
cv.put(SimplesSQLHelper.COLUNA_GOLONE, simplao.golone);
cv.put(SimplesSQLHelper.COLUNA_GOLTWO, simplao.goldois);
long id = db.insert(SimplesSQLHelper.TABELA_SIMPLES, null, cv);
if (id != -1) {
simplao.id = id;
}
db.close();
return id;
}
public void salvar(SimplesBanco simplao) {
if (simplao.id == 0) {
inserir(simplao);
}
}
}
Simplessqlhelper
package BancoSimples;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SimplesSQLHelper extends SQLiteOpenHelper {
private static final String NOME_BANCO = "dbsimples";
private static final int VERSAO_BANCO = 1;
public static final String TABELA_SIMPLES = "result";
public static final String COLUNA_ID = "_id";
public static final String COLUNA_NOMEONE = "timeum";
public static final String COLUNA_NOMETWO = "timedois";
public static final String COLUNA_GOLONE = "golone";
public static final String COLUNA_GOLTWO = "goldois";
public SimplesSQLHelper(Context context){
super(context, NOME_BANCO, null, VERSAO_BANCO);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase){
sqLiteDatabase.execSQL(
"CREATE TABLE " + TABELA_SIMPLES + "(" + COLUNA_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUNA_NOMEONE + "TEXT NOT NULL,"
+ COLUNA_NOMETWO + "TEXT NOT NULL," + COLUNA_GOLONE + "TEXT NOT NULL," + COLUNA_GOLTWO + "TEXT NOT NULL)"
);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion){
//para as proximas versões
}
}
activity_simple.xml
import BancoSimples.SimplesBanco;
import BancoSimples.SimplesRepositorio;
import BancoSimples.SimplesSQLHelper;
public void SalvarR (SimplesBanco simplao){
SimplesRepositorio repo = new SimplesRepositorio(this);
repo.salvar(simplao);
setResult(RESULT_OK);
}
missing post error log, see in Logcat and post here again
– Alessandro Barreto