【问题标题】:syntax error on token "(" , ; expected [closed]令牌“(”,;预期的语法错误[关闭]
【发布时间】:2012-08-02 13:07:55
【问题描述】:

我正在尝试修改 google 的 openGL 示例,但出现错误

syntax error on token "(" , ; expected

代码:

public class MyGLRenderer implements GLSurfaceView.Renderer 
{

    private static final String TAG = "MyGLRenderer";
    private Triangle mTriangle;
    private Square[] mSquare;

    private final float[] mMVPMatrix = new float[16];
    private final float[] mProjMatrix = new float[16];
    private final float[] mVMatrix = new float[16];
    private final float[] mRotationMatrix = new float[16];

    // Declare as volatile because we are updating it from another thread
    public volatile float mAngle;

    public void onSurfaceCreated(GL10 unused, EGLConfig config)
    {

        // Set the background frame color
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

        mTriangle = new Triangle();
        InitalizeSquares();
    }

    public void InitalizeSquares()
    {
         mSquare  = new Square[100];
         for(int i = 0; i < 10; i++)
         {
            for(int j = 0; j < 10; j++)
            {
                float[] pos = {j,i,0};
                mSquare[i*10 + j].SetPos(pos);
            }
         }
    }

    //Error here 
    public void onDrawFrame(GL10 unused){


        // Draw background color
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        // Set the camera position (View matrix)
        Matrix.setLookAtM(mVMatrix, 0, 0, 0, -10, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

        // Calculate the projection and view transformation
        Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 10; j++)
            {
                // Draw square
                mSquare[i*10 + j].draw(mMVPMatrix);
            }
        }

        // Create a rotation for the triangle
        //        long time = SystemClock.uptimeMillis() % 4000L;
        //        float angle = 0.090f * ((int) time);
        Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

        // Combine the rotation matrix with the projection and camera view
        Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

        // Draw triangle
        mTriangle.draw(mMVPMatrix);
    }

【问题讨论】:

  • 当您在函数的第一行看到; expected 时,该错误几乎可以肯定是上述方法中缺少}
  • 据我所知,您的代码中没有任何内容会导致该错误。它是在哪一行引起的,前面的代码是什么?
  • 我在 public void onDrawFrame(GL10 used){

标签: java android eclipse


【解决方案1】:

尝试清理构建。有时这就是清理莫名其妙的语法错误所需要的全部内容。

【讨论】:

  • 这就是解决方案。这是我对 Eclipse 和 Java 的第一次破解,所以这是一个我不知道会发生的奇怪错误。
【解决方案2】:

试试

// Combine the rotation matrix with the projection and camera view
        Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

        // Draw triangle
        mTriangle.draw(mMVPMatrix);
    } 
}

【讨论】:

  • 这个函数下的类还有很多。我确实试过了,它说'令牌“}”上的语法错误删除这个令牌'
猜你喜欢
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 2012-04-14
  • 1970-01-01
相关资源
最近更新 更多