這裏是我的管理Bean類,無法實例類錯誤JSF,引起NullPointerException異常
public class ChartBean implements Serializable {
private PieChartModel pieModel;
public ChartBean(){
createPieModel();
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel(){
try {
pieModel = new PieChartModel();
String query = "SELECT b.countryname,count(b.countryname) FROM info.summery a,info.countrymcc b;";
Connector conn = new Connector();
Statement str = (Statement) conn.getConn().createStatement();
ResultSet res = str.executeQuery(query);
while(res.next()){
pieModel.set(res.getString(1), Integer.parseInt(res.getString(2)));
}
} catch (SQLException ex) {
Logger.getLogger(ChartBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
但問題是,當它被編譯它給這樣的「廣東話實例化類錯誤:組織。 primefaces.examples.view.ChartBean」。是什麼原因??
堆棧跟蹤:
Caused by: java.lang.NullPointerException at
org.primefaces.examples.view.ChartBean.createPieModel(ChartBean.java:45) at
org.primefaces.examples.view.ChartBean.<init>(ChartBean.java:32) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI
mpl.java:39) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorA
ccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at
java.lang.Class.newInstance0(Class.java:355) at java.lang.Class
嘗試在構造函數中沒有盡全力。從構造函數中刪除對createPieModel()的調用,並使用@PostConstruct對createPieModel()進行註釋 –
我會嘗試一下,然後給出這樣的錯誤:「在託管bean chartBean上執行資源注入時發生錯誤」。 – user1705260
爲什麼不使用ORM模型,即使使用JPA或Hibernate等Java EE? – Lion