【问题标题】:"void is an invalid type for the variable paintSquare" error [closed]“void 是变量paintSquare 的无效类型”错误[关闭]
【发布时间】:2015-01-13 19:10:09
【问题描述】:

我正在为我的 AP Comp Sci 课程制作一个名为“Titris”的俄罗斯方块克隆,并且在遇到任何错误时我得到了这个。它来自这段代码

private void paintSquare(Graphics g1, int x, int y) { Color color = matrix[y][x]; int xMin = x * squareSize.width; int yMin = y * squareSize.height; int xMax = xMin + squareSize.width - 1; int yMax = yMin + squareSize.height - 1; int i; bufferRect.x = xMin; bufferRect.y = yMin; bufferRect.width = squareSize.width; bufferRect.height = squareSize.height; if (!bufferRect.intersects(g1.getClipBounds())) { return; }

来自paintSquare的错误

请帮忙,这个项目很快就要到期了,我不知道该怎么处理这个错误。

【问题讨论】:

  • 以后在询问无法编译的代码时,您应该包括来自编译器的错误。
  • 为什么你的方法减速后有个分号?

标签: java variables void tetris


【解决方案1】:

删除参数列表后的分号。

private void paintSquare(Graphics g1, int x, int y) {

【讨论】:

    【解决方案2】:
    private void paintSquare(Graphics g1, int x, int y); {
    

    应该是

    private void paintSquare(Graphics g1, int x, int y) {
    

    参数后面的分号会破坏你的代码。

    【讨论】:

    • 给你 +1 解释为什么 ;必须删除
    • 执行此操作后仍然出现相同的错误。
    • @djdarkfiasco 你的逻辑一定是错的
    • 你能把那个函数中的所有代码贴出来吗?
    • 更新了函数所在的全部代码
    猜你喜欢
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    相关资源
    最近更新 更多