DBFlow选择列

时间:2015-11-21 04:00:59

标签: android mysql android-studio orm

我有一个由不同列组成的表 我在选择特定列时遇到此错误。

java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.juandirection.ModelPoi.POIType' on a null object reference

获取特定列值的代码是这样的。

String type = (new Select(ModelPoi$Table.POITYPE).from(ModelPoi.class).where(Condition.column(ModelPoi$Table.POILAT).is(Global.lat)).querySingle()).POIType;  

对于我的数据库表。

import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;

/**
 * Created by Galvez on 11/17/2015.
 */
@Table(databaseName = JuanDirectionDB.dbName)
public class ModelPoi extends BaseModel {
    @Column
    @PrimaryKey(autoincrement = true)
    long getId;

    @Column
    String POI;

    @Column
    String POIAddress;

    @Column
    String POILat;

    @Column
    String POILong;

    @Column
    String POIType;

    @Column
    String POIInfo;
}

1 个答案:

答案 0 :(得分:0)

尝试使用您的代码。

Select select = new Select(ModelPoi$Table.POITYPE).from(ModelPoi.class).where(Condition.column(ModelPoi$Table.POILAT).is(Global.lat)).querySingle();

String type = select!=null ? select.POIType : "NO_RESULT";
相关问题