我正在尝试根据形状绘制图形,该形状获取点的几何形状并在选择此几何形状“承载”的行后更改其颜色问题是每次选择行时都会出现此错误这是日志文件:谢谢提前
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.vividsolutions.jump.workbench.ui.renderer.java2D.Java2DConverter.toShape(Java2DConverter.java:313)
at com.vividsolutions.jump.workbench.ui.plugin.specific.SearchPropertiesPlugin$2.valueChanged(SearchPropertiesPlugin.java:144)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:147)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:194)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:388)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:398)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:442)
at javax.swing.JTable.changeSelectionModel(JTable.java:2352)
at javax.swing.JTable.changeSelection(JTable.java:2421)
at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(BasicTableUI.java:1085)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:1008)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
at java.awt.Component.processMouseEvent(Component.java:6294)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4233)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:627)
at java.awt.EventQueue$2.run(EventQueue.java:625)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:641)
at java.awt.EventQueue$3.run(EventQueue.java:639)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
这是此错误所涉及的代码行,它发生在包含bornes(Name,X,Y)的bornesTable的侦听器中
searchProperties.getBornesTable().getSelectionModel().addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent e) {
try {
if (search()!= null){
// here's the line 144 in toShape() method
final Shape shape = context.getLayerViewPanel().getViewport().getJava2DConverter().toShape(selectedBornes());
Color color = Color.yellow;
Stroke stroke =new BasicStroke(5, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
final Graphics2D graphics = (Graphics2D) context.getLayerViewPanel().getGraphics();
graphics.setColor(color);
//graphics.setXORMode(Color.white);
graphics.setStroke(stroke);
graphics.fill(shape);
}
else
JOptionPane.showMessageDialog(null, "vous n'avez pas selectionner une bornes " );
} catch (NoninvertibleTransformException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
这是方法: selectedBornes()
public Geometry selectedBornes() {
if (getSelectedRowIndex()> 0)
{
Geometry geometry;
geometry = searchBorne().get(getSelectedRowIndex()).getGeometry();
return geometry;
}
return null;
}
和方法 serchBornes() 没有问题,但我会发布它
private List<BasicFeature> searchBorne() {
final List<BasicFeature> basicFeatureBornes = new ArrayList<BasicFeature>();
for(BasicFeature basicFeature : BornesList) {
if ( searchProperties.getNumTextField().getText().equals(basicFeature.getString("num")) &&
searchProperties.getComplementComboBox().getSelectedItem().equals(basicFeature.getString("complement")))
basicFeatureBornes.add(basicFeature);
}
return basicFeatureBornes;
}
和 getSelectedRowIndex() 方法也没有问题,但我会发布它
public int getSelectedRowIndex() {
int row = 0;
for(int i = 0; i < searchBorne().size() ; i++ ) {
row = searchProperties.getBornesTable().getSelectedRow();
}
return row;
}