生成项目时会议室数据库错误

时间:2018-07-16 13:27:02

标签: android android-room android-databinding

我猜我的房间数据库有问题。

我创建了一个实体类:

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.os.Parcel;
import android.os.Parcelable;

@Entity
public class Supplier implements Parcelable {

    @PrimaryKey(autoGenerate = true)
    private Long id;

    private String mastro;
    private String partitario;
    private String description;

    // region Construction

    public Supplier() {
        super();
    }

    // region Public getters and setters

    protected Supplier(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readLong();
        }
        mastro = in.readString();
        partitario = in.readString();
        description = in.readString();
    }

    public static final Creator<Supplier> CREATOR = new Creator<Supplier>() {
        @Override
        public Supplier createFromParcel(Parcel in) {
            return new Supplier(in);
        }

        @Override
        public Supplier[] newArray(int size) {
            return new Supplier[size];
        }
    };

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getMastro() {
        return mastro;
    }

    public void setMastro(String mastro) {
        this.mastro = mastro;
    }

    public String getPartitario() {
        return partitario;
    }

    public void setPartitario(String partitario) {
        this.partitario = partitario;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(id);
        }
        dest.writeString(mastro);
        dest.writeString(partitario);
        dest.writeString(description);
    }

    // endregion
}

然后我用简单的查询创建一个Dao类:

@Dao
public interface SupplierDao {

    @Query("SELECT * FROM Supplier WHERE id = :id")
    Supplier getById(Long id);

    @Insert
    Long insert(Supplier supplier);

    @Insert
    Long insert(List<Supplier> suppliers);

    @Update
    void update(Supplier supplier);

    @Delete
    void delete(Supplier supplier);

    @Query("DELETE FROM Supplier")
    void deleteAll();
}

这是我创建数据库时的类:

package com.poltronesofa.plt.storage;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverter;
import android.arch.persistence.room.TypeConverters;
import android.content.Context;

import com.poltronesofa.plt.storage.dao.AnomalyDao;
import com.poltronesofa.plt.storage.dao.ContractorDao;
import com.poltronesofa.plt.storage.dao.LoadingPlanDao;
import com.poltronesofa.plt.storage.dao.ProductDao;
import com.poltronesofa.plt.storage.dao.SupplierDao;
import com.poltronesofa.plt.storage.dao.UsersDao;
import com.poltronesofa.plt.storage.model.Anomaly;
import com.poltronesofa.plt.storage.model.Contractor;
import com.poltronesofa.plt.storage.model.LoadingPlan;
import com.poltronesofa.plt.storage.model.Product;
import com.poltronesofa.plt.storage.model.Supplier;
import com.poltronesofa.plt.storage.model.User;

import java.util.Date;

/**
 * @author arinaldi
 */
@Database(entities = {User.class, LoadingPlan.class, Contractor.class, Product.class, Anomaly.class, Supplier.class}, version = PLTDatabase.DB_VERSION, exportSchema = false)
@TypeConverters({PLTDatabase.Converters.class})
public abstract class PLTDatabase
        extends RoomDatabase {

    static final String DB_NAME = "plt_db";
    static final int DB_VERSION = 1;

    private static PLTDatabase INSTANCE = null;

    public static void init(Context context) {
        if (INSTANCE != null) {
            INSTANCE.close();
        }

        INSTANCE = Room.databaseBuilder(context, PLTDatabase.class, DB_NAME)
                .allowMainThreadQueries()
                .build();
    }

    public static PLTDatabase get() {
        if (INSTANCE == null) {
            throw new RuntimeException("DATABASE not initialized");
        }

        return INSTANCE;
    }

    public void clear() {
        users().deleteAll();
        loadingPlans().deleteAll();
        contractors().deleteAll();
        products().deleteAll();
        anomalies().deleteAll();
        //suppliers().deleteAll();
    }

    public abstract UsersDao users();

    public abstract LoadingPlanDao loadingPlans();

    public abstract ContractorDao contractors();

    public abstract ProductDao products();

    public abstract AnomalyDao anomalies();

    public abstract SupplierDao suppliers();

    public static class Converters {

        @TypeConverter
        public Date fromTimeStamp(Long timestamp) {
            return timestamp == null ? null : new Date(timestamp);
        }

        @TypeConverter
        public Long toTimeStamp(Date date) {
            return date == null ? null : date.getTime();
        }
    }
}

编译时,我收到与数据绑定相关的错误,由于未指定错误,因此无法返回到真正的错误:

C:/Documents/Android Studio/PLT 
app/build/generated/data_binding_base_class_source_out/devDebug/dataBindingGenBaseClassesDevDebug/out   
com/poltronesofa/plt/databinding/ActivityHomeBinding.java   
error: cannot find symbol class DataBindingComponent    
error: cannot find symbol class DataBindingComponent    
error: cannot find symbol class DataBindingComponent    
error: cannot find symbol class DataBindingComponent    
com/poltronesofa/plt/databinding/ViewToolbarBinding.java    
com/poltronesofa/plt/databinding/FragmentWelcomeBinding.java    
com/poltronesofa/plt/databinding/ListItemLoadingPlanBinding.java    
com/poltronesofa/plt/databinding/FragmentLoadingPlansBinding.java   
com/poltronesofa/plt/databinding/ActivityLoginBinding.java  
com/poltronesofa/plt/databinding/ActivityCheckTissueBinding.java    
com/poltronesofa/plt/databinding/ActivitySuppliersBinding.java  
com/poltronesofa/plt/databinding/ListItemSupplierBinding.java   
com/poltronesofa/plt/databinding/ActivityContractorsBinding.java    
com/poltronesofa/plt/databinding/ListItemContractorBinding.java 
com/poltronesofa/plt/databinding/ActivityLoadingPlanBinding.java    
com/poltronesofa/plt/databinding/ActivityProductDetailBinding.java  
com/poltronesofa/plt/databinding/ActivityProductsBinding.java   
com/poltronesofa/plt/databinding/ListItemProductBinding.java    
com/poltronesofa/plt/databinding/ActivitySettingsBinding.java   
com/poltronesofa/plt/databinding/ActivitySplashBinding.java 
com/poltronesofa/plt/databinding/FragmentProductBinding.java    
com/poltronesofa/plt/databinding/ListItemArticleBinding.java    
app/src/main/java   
com/poltronesofa/plt/storage/dao/SupplierDao.java   
error: Method returns long but it should return one of the following: `void, long[], java.lang.Long[], java.util.List<java.lang.Long>`. If you want to return the list of row ids from the query, your insertion method can receive only 1 parameter.

我该如何解决?

0 个答案:

没有答案