chennaione / sugar

Insanely easy way to work with Android Database.
http://satyan.github.com/sugar/
MIT License
2.62k stars 583 forks source link

java.lang.NullPointerException when I try to save entity #743

Open ALAxHxC opened 7 years ago

ALAxHxC commented 7 years ago

Hi, im integrate sugar: in my manifest:

 <meta-data android:name="DATABASE" android:value="ubicaciones.db" />
        <meta-data android:name="VERSION" android:value="1" />
        <meta-data android:name="QUERY_LOG" android:value="true" />
        <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.procibernetica.moca" />

My entity

public class Ubicacion  extends SugarRecord{
     double lat;
     double len;
     float velocidad;
     String proveedor;
     String tipo;
     float distancia_last;
     int dia;
     int mes;
     int year;
     int hora_local;

    public Ubicacion() {
    }

    public Ubicacion(double lat, double len, float velocidad,
                     String proveedor, String tipo,
                     float distancia_last, int dia,
                     int mes, int year,
                     int hora_local) {
        this.lat = lat;
        this.len = len;
        this.velocidad = velocidad;
        this.proveedor = proveedor;
        this.tipo = tipo;
        this.distancia_last = distancia_last;
        this.dia = dia;
        this.mes = mes;
        this.year = year;
        this.hora_local = hora_local;
    }

But when I try to save

 Ubicacion ub=  new Ubicacion(location.getLatitude(),location.getLongitude(),location.getSpeed(),
                location.getProvider(), TiposDeUbicacionPorHora.tipoDeUbicaciones(location,cal),
                location.distanceTo(ServicioTracking.mLastLocation),
                cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.MONTH),cal.get(Calendar.YEAR),
                cal.get(Calendar.HOUR_OF_DAY));
        ub.save();

Show me error in

ub.save();

In my grade:

compile 'com.github.satyan:sugar:1.3'

kigen commented 7 years ago

@ALAxHxC If you can please post the error that you are encountering. It will be helpful figuring out what's wrong.

In the meantime try turning off instant run on android studio.

liko28s commented 7 years ago

Do you have the Instant Run disabled? In your first execution disable Instant Run on Android Studio. And, can you post complete manifest? remind use <application android:label="@string/app_name" android:icon="@drawable/icon" android:name="com.orm.SugarApp"> or if you use a custom App Class extend com.orm.SugarApp and override the methods