0

ORMlite を使用して、Android の sqlite に日付を保存しています。Data の POJO クラスを作成しました。Time オブジェクトまたは Date オブジェクトのメンバー変数を作成すると、NullPointerException が発生します。

これは私のPojoクラスです

@DatabaseTable(tableName="user_prior_commitment")
public class PreferencesPriorCommitmentRowData {

    // id is generated by the database and set on the object automagically
    @DatabaseField(generatedId = true)
    int id;
    @DatabaseField(index = true)
    int user_id;
    @DatabaseField
    String description;

    @DatabaseField
    String location;
    @DatabaseField
    Date date;
    @DatabaseField
    String start_time;
    @DatabaseField
    String end_time;
    @DatabaseField
    int lattitude;
    @DatabaseField
    int longitude;
    ...        

そして、手動でこのテーブルを使用してデータベースを作成し、アクティビティで以下のコードを使用します

DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
DatabaseHelper db = manager.getHelper(context);
Dao<PreferencesPriorCommitmentRowData, Integer> simpleDao =
    db.getPreferencesPriordataDao();
List<PreferencesPriorCommitmentRowData>aa = simpleDao.queryForAll();

しかし、最後の行の前に、Null Pointer Exception が発生します。

これに関して親切に助けてください。

4

1 に答える 1

1

タイプは、データベース内の対応するタイプにjava.util.Dateマップする必要DATETIMEがあります。私はそれがあなたの問題を解決するはずだと思います。

于 2011-08-23T05:02:17.360 に答える