我正在开发一个简单的 java 游戏,我的滚动条引发了异常。滚动条应该是一个“游戏滑块”。
线程“Thread-3”java.lang.ClassCastException 中的异常:sun.java2d.d3d 的 sun.java2d.d3d.D3DRenderer.copyArea(未知来源)处的 sun.java2d.NullSurfaceData 无法转换为 sun.java2d.d3d.D3DSurfaceData .D3DSurfaceData.copyArea(Unknown Source) at sun.java2d.SunGraphics2D.doCopyArea(Unknown Source) at sun.java2d.SunGraphics2D.copyArea(Unknown Source) at javax.swing.BufferStrategyPaintManager.copyArea(Unknown Source) at javax.swing.RepaintManager .copyArea(Unknown Source) at javax.swing.JViewport.blitDoubleBuffered(Unknown Source) at javax.swing.JViewport.windowBlitPaint(Unknown Source) at javax.swing.JViewport.setViewPosition(Unknown Source) at javax.swing.plaf.basic .BasicScrollPaneUI$Handler.hsbStateChanged(Unknown Source) at javax.swing.plaf.basic。BasicScrollPaneUI$Handler.stateChanged(Unknown Source) at javax.swing.DefaultBoundedRangeModel.fireStateChanged(Unknown Source) at javax.swing.DefaultBoundedRangeModel.setRangeProperties(Unknown Source) at javax.swing.DefaultBoundedRangeModel.setValue(Unknown Source) at javax.swing。 JScrollBar.setValue(Unknown Source) at GameEnvironment.GamePanel.gameUpdate(GamePanel.java:171) at GameEnvironment.GamePanel.run(GamePanel.java:73) at java.lang.Thread.run(Unknown Source)GamePanel.gameUpdate(GamePanel.java:171) 在 GameEnvironment.GamePanel.run(GamePanel.java:73) 在 java.lang.Thread.run(未知来源)GamePanel.gameUpdate(GamePanel.java:171) 在 GameEnvironment.GamePanel.run(GamePanel.java:73) 在 java.lang.Thread.run(未知来源)
代码行如下:
if (reachedMiddle)
scrollPane.getHorizontalScrollBar().setValue(player.getX() - (widthHorizontalScrollBar / 2));
异常将或多或少随机引发。到目前为止我还没有想通。