My application is closing when starting the screen with database

2

My activity with the database has a problem, because I created class right and Android Studio is not showing any errors, but when I run it on the mobile when opening activity that has the bank of data it closes.

Would anyone have any idea what it is?

package BankSimples (bank)

Simple Bank

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;
    }
}

SimpleRepository

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);
    }
 }
}

SimpleSQLHelper

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_simples.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);
    }
    
asked by anonymous 05.10.2016 / 03:34

1 answer

1

Nathan

It's very difficult to figure out the error without the log, but we're going to try to go and see where the error is. First, let's take a look at this in your table-creation SQL because there are missing spaces in it when concatenating the string with the variables

"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)"

Let's look at the COLUNA_NOMEONE + "TEXT NOT NULL," excerpt, when concatenating, there will be no space between the column name and the TEXT type, resulting in something like colunaumTEXT NOT NULL . Note that you have several cases like this in your SQL above.

Anything if that alone does not solve, comment below to find out.

    
05.10.2016 / 14:16