我想在我的@ManagedBean
课程中使用服务层,但我已经NullPointerException
了。
这是我的界面
@Remote
public interface FieldService {
void insertField(Field field);
List<Field> getListOfFields();
Field getFieldByTitle(String title);
void removeField(Field field);
}
这是我对这个界面的实现
@Stateless
public class FieldServiceImpl implements FieldService {
private FieldDao fieldDao = new FieldDaoImpl();
public void insertField(Field field) {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
fieldDao.insertField(field, session);
session.getTransaction().commit();
} catch (Exception e) {
session.getTransaction().rollback();
} finally {
closeSession(session);
}
}
public List<Field> getListOfFields() {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
return fieldDao.getListOfFields(session);
} catch (Exception e) {
return new ArrayList<Field>();
} finally {
closeSession(session);
}
}
public Field getFieldByTitle(String title) {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
return fieldDao.getFieldByTitle(title, session);
} catch (Exception e) {
return null;
} finally {
closeSession(session);
}
}
public void removeField(Field field) {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
fieldDao.removeField(field, session);
session.getTransaction().commit();
} catch (Exception e) {
session.getTransaction().rollback();
} finally {
closeSession(session);
}
}
private void closeSession(Session session) {
if (Objects.nonNull(session)) {
session.close();
}
}
}
这是我的FieldManageBean
课程
@ManagedBean(name = "fieldManageBean")
@RequestScoped
public class FieldManageBean {
private Field field;
@EJB
private FieldService fieldService;
@PostConstruct
public void init() {
field = new Field();
}
public void addField() {
System.out.println(field);
fieldService.insertField(field);
}
public List<String> getFieldTypes() {
return Type.getStringListOfEnums();
}
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
}`
当我尝试将addField()
函数调用到我的xhtml页面时,它会在NullPointerException
fieldService.insertField(field);
给我typedef struct {
uint32_t power : 3;
uint32_t reserved : 24;
uint32_t speed : 5;
} ctrl_t;
void set_ctrl()
{
ctrl_t r = {
.power = 1;
.speed = 22;
.reserved = 0;
}
uint32_t *addr = 0x12345678;
*addr = *((uint32_t *) &r);
return;
}
问题是什么?