Java 标记“”上的语法错误;(“预期的”
我试图修改google的openGL示例,但我得到了一个错误Java 标记“”上的语法错误;(“预期的”,java,android,eclipse,Java,Android,Eclipse,我试图修改google的openGL示例,但我得到了一个错误 syntax error on token "(" , ; expected 守则: public class MyGLRenderer implements GLSurfaceView.Renderer { private static final String TAG = "MyGLRenderer"; private Triangle mTriangle; private Square[] mSqu
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);
}
公共类MyGLRenderer实现GLSurfaceView.Renderer
{
私有静态最终字符串标记=“MyGLRenderer”;
私人三角三角;
私人广场[]mSquare;
私有最终浮动[]mMVPMatrix=新浮动[16];
私有最终浮动[]mProjMatrix=新浮动[16];
私有最终浮动[]mVMatrix=新浮动[16];
私有最终浮动[]mRotationMatrix=新浮动[16];
//声明为volatile,因为我们正在从另一个线程更新它
公共垃圾桶;
已创建Surface上的公共void(GL10未使用,EGLConfig配置)
{
//设置背景框颜色
GLES20.glClearColor(0.0f,0.0f,0.0f,1.0f);
mTriangle=新三角形();
初始化方();
}
公共void initializeSquares()
{
mSquare=新正方形[100];
对于(int i=0;i<10;i++)
{
对于(int j=0;j<10;j++)
{
float[]pos={j,i,0};
mSquare[i*10+j].SetPos(pos);
}
}
}
//这里出错
公共框架(GL10未使用){
//绘制背景色
GLES20.glClear(GLES20.GLU颜色缓冲位);
//设置相机位置(视图矩阵)
setLookAtM(mVMatrix,0,0,0,-10,0f,0f,0f,0f,1.0f,0.0f);
//计算投影和视图变换
多重矩阵(mMVPMatrix,0,mProjMatrix,0,mVMatrix,0);
对于(int i=0;i<10;i++)
{
对于(int j=0;j<10;j++)
{
//画正方形
mSquare[i*10+j].绘制(mMVPMatrix);
}
}
//为三角形创建旋转
//长时间=SystemClock.uptimeMillis()%4000L;
//浮动角度=0.090f*((int)时间);
旋转矩阵(旋转矩阵,0,mAngle,0,0,-1.0f);
//将旋转矩阵与投影视图和摄影机视图相结合
multiplyMM(mMVPMatrix,0,mRotationMatrix,0,mMVPMatrix,0);
//画三角形
M三角图(MMVP矩阵);
}
试试看
尝试清理构建。有时,这就是清理无法解释的语法错误所需的全部工作。当您在函数的第一行看到
;预期的,几乎可以肯定错误是丢失的)
在上面的一个方法中。从我所看到的,您的代码中没有任何东西会导致该错误。它是在哪一行上引起的,在那之前的代码是什么?我在public void onDrawFrame(GL10 unused)行上得到错误{这个函数下还有更多的类。我尝试过,它说“syntax error on token”}删除这个标记“这就是解决方案。这是我第一次破解Eclipse和Java,所以我不知道会发生一个奇怪的bug。”。
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
// Draw triangle
mTriangle.draw(mMVPMatrix);
}
}