这是我的托管Bean类,
公共类MapBean实现Serializable {
private MapModel polylineModel;
public MapBean() {
createMap();
}
public void createMap(){
try {
polylineModel = new DefaultMapModel();
LatLng coord;
String query = "select a.lan,a.lat from country;";
Connector conn = new Connector();
Statement str = (Statement) conn.getConn().createStatement();
ResultSet res = str.executeQuery(query);
Polyline polyline1;
polyline1 = new Polyline();
while(res.next()){
coord= new LatLng(Integer.parseInt(res.getString(2)), Integer.parseInt(res.getString(1)));
polyline1.getPaths().add(coord);
}
polyline1.setStrokeWeight(10);
polyline1.setStrokeColor("#FF9900");
polyline1.setStrokeOpacity(0.7);
polylineModel.addOverlay(polyline1);
} catch (SQLException ex) {
Logger.getLogger(MapBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
public MapModel getPolylineModel() {
return polylineModel;
}
public void onPolylineSelect(OverlaySelectEvent event) {
addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Polyline Selected", null));
}
public void addMessage(FacesMessage message) {
FacesContext.getCurrentInstance().addMessage(null, message);
}
} 但问题是当它被编译时会产生类似“Cant instantiate class:org.primefaces.examples.view.MapBean”的错误。是什么原因?
答案 0 :(得分:1)
如果LatLng支持double,则使用此代码。
coord= new LatLng(Double.parseDouble(res.getString(2)), Double.parseDouble(res.getString(1)));