2015-11-21 63 views
0

我有一張由不同列組成的表格。
選擇特定列時出現此錯誤。DBFlow選擇列

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

回答

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