我正在为UUID获得NPE,我不知道为什么

时间:2016-06-06 22:20:17

标签: android

   public Crash getCrash() {
    String uuidString = getString(getColumnIndex(CrashTable.Cols.UUID));
    String name = getString(getColumnIndex(CrashTable.Cols.DRIVER1));
    String insCo = getString(getColumnIndex(CrashTable.Cols.INSCO));
    String policy = getString(getColumnIndex(CrashTable.Cols.POLICY));
    String telephone = getString(getColumnIndex(CrashTable.Cols.PHONE));
    String email = getString(getColumnIndex(CrashTable.Cols.EMAIL));

    **Crash crash = new Crash(UUID.fromString(uuidString));**
    crash.setYourName(name);
    crash.setInsCo(insCo);
    crash.setPolicy(policy);
    crash.setTelephone(telephone);
    crash.setEmail(email);

    return crash;
}

我标记的行导致NPE(uuid == null)。它似乎与fromString有问题。这是" Crash"的相关部分。将它引用。

public class Crash  {

private UUID mId;
private String mYourName;
private String mInsCo;
private String mPolicy;
private String mTelephone;
private String mEmail;
private Date mDate;

public Crash() {
    this(UUID.randomUUID());
}

public Crash(UUID id) {
    mId = id;
    mDate = new Date();
}

public UUID getId() {
    return mId;
}

我有什么遗失的东西吗?我对此非常陌生,所以如果您需要更多信息,请告诉我们。提前谢谢。

1 个答案:

答案 0 :(得分:0)

检查您传入的uuid字符串是否为空。

如果它不为null,请检查您正在使用的uuid字符串的格式。

UUID转换的示例:

// creating UUID      
UUID uid = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d");