AdministratorFrame(Administrator account) {
AdministratorFrameLocked(true);
administrator = account;
EntityManagerFactory entityManagerFactory
= Persistence.createEntityManagerFactory("KwestionariuszForRoot");
EntityManager entityManager
= entityManagerFactory.createEntityManager();
List<Company> companies
= entityManager.createNamedQuery("Company.findByAdministratorId")
.setParameter("administrator_id", administrator).getResultList();
entityManager.close();
System.out.println(companies);
List<String> companyNames = new ArrayList<>();
for (Company company : companies) {
companyNames.add(company.getName().toString());
}
System.out.println(companyNames);
String[] companiesArray = new String[companyNames.size()];
companiesArray = companyNames.toArray(companiesArray);
System.out.println(companiesArray);
jComboBoxCompaniesByName
.setModel(new javax.swing.DefaultComboBoxModel(companiesArray));
initComponents();
AdministratorFrameLocked(false);
}
返回(注意 printlns 返回一个值,所以不为空):
[model.Company[ id=1 ]]
[Mentor]
[Ljava.lang.String;@139fcc0
Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException at
frames.AdministratorFrame.<init>(AdministratorFrame.java:54)
第 54 行是:
jComboBoxCompaniesByName
.setModel(new javax.swing.DefaultComboBoxModel(companiesArray));
我究竟做错了什么?