Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 尝试在Google App Engine中获取实体中字段的值时出现NullPointerException异常_Java_Google App Engine_Google Cloud Platform_Google Cloud Datastore_Objectify - Fatal编程技术网

Java 尝试在Google App Engine中获取实体中字段的值时出现NullPointerException异常

Java 尝试在Google App Engine中获取实体中字段的值时出现NullPointerException异常,java,google-app-engine,google-cloud-platform,google-cloud-datastore,objectify,Java,Google App Engine,Google Cloud Platform,Google Cloud Datastore,Objectify,我有一个学生实体,其中有一个字段,是对像这样的部门实体的引用。 @Load private@Index Ref部门 然后Department字段的getter和setter如下所示 public Department getDepartment() { return department.get(); } public void setDepartment(Key<Department> department) { this.department = Ref.cr

我有一个学生实体,其中有一个字段,是对像这样的部门实体的引用。
@Load private@Index Ref部门
然后Department字段的getter和setter如下所示

 public Department getDepartment() {
    return department.get();
}

public void setDepartment(Key<Department> department) {
    this.department = Ref.create(department);
}
@Index
private Key<SchoolFaculty> schoolFaculty;
 public String getSchoolFaculty() {
    return schoolFaculty.toWebSafeString();
}


public void setSchoolFaculty(Key<SchoolFaculty> schoolFaculty) {
    this.schoolFaculty = schoolFaculty;
}

我正在为数据存储事务使用objectify,并且添加了对objectify依赖项的所有引用。

因为
student.getDepartment().getSchoolFaculty()
在触发条件语句之前抛出null指针,而google appengine key无法为null实体或WebSafesting创建密钥。因此,请仔细调试并检查
getDepartment()
是否返回null或它首先返回的内容,如果您想创建一个带有数据存储的key的null字段,那么使用key就是使用默认值

Key.create(SchoolFaculty.class, "default"); // when it is null

希望这是有用的

,因为
student.getDepartment().getSchoolFaculty()
在触发条件语句之前抛出null指针,并且google appengine键无法为null实体或WebSafesting创建键。因此,请仔细调试并检查
getDepartment()
是否返回null或它首先返回的内容,如果您想创建一个带有数据存储的key的null字段,那么使用key就是使用默认值

Key.create(SchoolFaculty.class, "default"); // when it is null

希望这是有用的

,因为
student.getDepartment().getSchoolFaculty()
在触发条件语句之前抛出了null指针,而google appengine键无法为null实体或WebSafestring创建键,因为
student.getDepartment().getSchoolFaculty()
在触发条件语句之前抛出空指针,并且google appengine key无法为空实体创建键,或者websafestringgetDepartment()返回的是web安全字符串而不是Department实体。getDepartment()返回的是web安全字符串而不是Department实体。
 student.setDepartment(Key.create(Department.class,student_programme.getDepartmentRef()));// student_programme is a reference to an Entity which I use to get the department and it works fine and the student gets its Department set to the Department Value.
        if(student.getDepartment().getSchoolFaculty()) != null){     student.setSchoolFaculty(Key.create(SchoolFaculty.class,getDepartment().getSchoolFaculty()));}// this  is the line throws a null pointer Exception
Key.create(SchoolFaculty.class, "default"); // when it is null