DBFlow Select Column



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

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

尝试将代码作为.

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

最新更新