java 令牌上的语法错误,而是期望 variableDeclarator
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14266565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error on tokens, variableDeclarator expected instead
提问by Hollis Scriber
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(colDeptID, 1);
cv.put(colDeptName, "Sales");
db.insert(deptTable, colDeptID, cv);
cv.put(colDeptID, 2);
cv.put(colDeptName, "IT");
db.insert(deptTable, colDeptID, cv);
db.close();
With this code, I am getting a red underline under the parenthesis after put in every line and getting this error: Syntax error on token "(", delete this token.
使用此代码,我在每行放入后在括号下得到一个红色下划线并收到此错误:标记“(”上的语法错误,删除此标记。
I also get an error that says: Syntax error on tokens, variableDeclarator expected instead. Any ideas? I've tried everything I know to do, and none of it worked.
我还收到一条错误消息:令牌上的语法错误,需要使用 variableDeclarator。有任何想法吗?我已经尝试了所有我知道的方法,但没有一个奏效。
Edit: I also get Syntax error on "close", identifier expected after this token
编辑:我也在“关闭”时收到语法错误,此令牌后预期的标识符
I copy and pasted this code from a tutorial and all the comments said it worked, but I've had quite a few problems out of it. Thanks for such quick replies.
我从教程中复制并粘贴了这段代码,所有评论都说它有效,但我遇到了很多问题。谢谢这么快的回复。
回答by Patricia Shanahan
Only declarations, such as:
仅声明,例如:
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
can be directly inside a class declaration. Non-declarations, such as:
可以直接在类声明中。非声明,例如:
cv.put(colDeptID, 1);
cv.put(colDeptName, "Sales");
db.insert(deptTable, colDeptID, cv);
must be inside a method, constructor, initializer block, or static initializer block. In this case they should probably be in a constructor or method.
必须在方法、构造函数、初始化程序块或静态初始化程序块内。在这种情况下,它们可能应该在构造函数或方法中。
回答by user2352923
By Variable Declarator ID, it means something like intor string. Example: int randomnum = 9
or something like that.
通过变量声明符ID,它的意思是int或string 之类的东西。示例:int randomnum = 9
或类似的东西。
Hope this helps!
希望这可以帮助!
回答by Akhil Nambiar
Put the code inside a method and not directly inside the class.
将代码放在方法中,而不是直接放在类中。
Like
喜欢
SomeRandomMethod(){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(colDeptID, 1);
cv.put(colDeptName, "Sales");
db.insert(deptTable, colDeptID, cv);
cv.put(colDeptID, 2);
cv.put(colDeptName, "IT");
db.insert(deptTable, colDeptID, cv);
db.close();
}