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は値を返すため、nullではないことに注意してください):
[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));
私は何が間違っているのですか?