public class Water {
private Graphic graphic;
private float speed;
private float distanceTraveled;
public Water(float x, float y, float direction)
{
speed = 0.7f;
graphic = new Graphic();
graphic.setType("WATER");
graphic.setX(x);
graphic.setY(y);
direction = graphic.getDirection(); //direction from Hero as water is fired
}
public Water update(int time)
{
graphic.draw();
return Water.this;
distanceTraveled; // this is where the error occured...
}
}
When I tried to call distanceTraveled, I am getting the error as:
Syntax error, insert «VariableDeclarators» to complete LocalVariableDeclaration
Miki
40.4k13 gold badges121 silver badges202 bronze badges
asked Mar 16, 2016 at 16:18
4
To make the Syntax error disappear and to assign a value to distanceTraveledmodify the method public Water update(int time) as follows:
public Water update(int time) {
graphic.draw();
distanceTraveled = 1; // assign a value before returning
return Water.this;
}
Maybe you should read a bit about Java and doing some tutorials, because this is very basic stuff (at least if I’m not getting you wrong).
answered Mar 16, 2016 at 16:37
mnillemnille
1,3304 gold badges16 silver badges20 bronze badges
2
You have to either print distanceTraveled or do any operation like increment. Don’t write only variable.
marc_s
721k173 gold badges1320 silver badges1442 bronze badges
answered Jun 4, 2022 at 7:55
1
CORRECT: <%! …code… %> (JSP DECLARATION)
WRONG : <% …code… %> (JSP SCRIPLET)
WRONG : <%= …code… %> (JSP EXPRESSION)
Example:
<!-- ------------------------------------- -->
<html><body><h1>
<%!
public static String fn(){
return( "[CORRECT:USE ! MARK]");
};
%>
<%= fn() %>
</h1></body></html>
<!-- ------------------------------------- -->
Using «<%» or «<%=» instead of «<%!» will get error:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [3] in the jsp file: [/index.jsp] Syntax
error, insert «VariableDeclarators» to complete
LocalVariableDeclaration
answered Jul 9, 2018 at 0:44
![]()
KANJICODERKANJICODER
3,47729 silver badges16 bronze badges
I’ve created a program to browse an excel file and modify it using windowbuilder and Apache POI.
I’ve created a public string for the file path, as follows.
public class UI {
public static String filename;
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("MS Excel Files", "xlsx");
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file= chooser.getSelectedFile();
filename=file.getAbsolutePath();
And Called the String to the main code to get the file path to continue the process.
public static void main (String[]args) throws Exception {
UI.filename;
File file= new File(filename);
FileInputStream fis= new FileInputStream (file);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1= wb.getSheetAt(0);
When I run the GUI, I get the following error message,
Syntax error, insert «VariableDeclarators» to complete LocalVariableDeclaration
filename cannot be resolved to a variable
new File(filename);
This part shoud be something like this
File file= new File("C:\Users\Desktop\Project\Data.xlsx");
Any suggestions in this regard will be appreciated.
I’ve created a program to browse an excel file and modify it using windowbuilder and Apache POI.
I’ve created a public string for the file path, as follows.
public class UI {
public static String filename;
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("MS Excel Files", "xlsx");
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file= chooser.getSelectedFile();
filename=file.getAbsolutePath();
And Called the String to the main code to get the file path to continue the process.
public static void main (String[]args) throws Exception {
UI.filename;
File file= new File(filename);
FileInputStream fis= new FileInputStream (file);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1= wb.getSheetAt(0);
When I run the GUI, I get the following error message,
Syntax error, insert «VariableDeclarators» to complete LocalVariableDeclaration
filename cannot be resolved to a variable
new File(filename);
This part shoud be something like this
File file= new File("C:\Users\Desktop\Project\Data.xlsx");
Any suggestions in this regard will be appreciated.
Содержание
- Generics и Comparable и Comparator. Синтаксическая ошибка, вставьте «;» для завершения LocalVariableDeclarationStatement»
- 4 ответы
- Syntax error insert to complete localvariabledeclarationstatement
- Breadcrumbs
Generics и Comparable и Comparator. Синтаксическая ошибка, вставьте «;» для завершения LocalVariableDeclarationStatement»
Этот вопрос касается дженериков и использования интерфейсов Comparable и Comparator.
У меня есть класс Шоколад:
И еще один класс Sorter с основным методом
Я получаю Ошибка в предпоследней строке написано: «Синтаксическая ошибка, вставьте «;», чтобы завершить LocalVariableDeclarationStatement». Что означает эта ошибка и как ее исправить?
задан 11 июн ’13, 00:06
вам нужно только добавить точку с запятой, вам нужно закрыть создание экземпляра Comparator, даже если это класс анонимуса. — nachokk
4 ответы
Вам всегда нужна точка с запятой для завершения объявления переменной, даже если вы создаете экземпляр анонимного класса.
Если бы у вас был, например, конкретный класс PairChocolateComparator , вы все равно использовали бы точку с запятой:
Поэтому вы все равно должны добавить точку с запятой для экземпляра анонимного класса:

Просто добавьте точку с запятой, как предлагает сообщение. Это завершение оператора присваивания (to interfaceChocolate ).

Да, это правильно, посмотрите на свой КОД, вы не использовали Semi Colleen для завершения анонимного класса, например, ваш код
это должно быть так.
посмотрите на ; что закончит класс
Надеюсь, что это поможет.

Иногда эта ошибка появляется (даже если у вас есть точка с запятой в конце объявления вашей переменной), потому что у вас есть специальный символ непосредственно под этим объявлением (например, *), который вызывает общую ошибку, подобную этой, в строке выше. Хоть что-то поискать. ну, а, поздоровайся со своим мотыльком от меня, а
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками java oop generics comparator comparable or задайте свой вопрос.
Источник
Syntax error insert to complete localvariabledeclarationstatement
Community
Participate
Eclipse IDE
Home » Newcomers » Newcomers » Syntax error, insert «;» to complete BlockStatements line 7 (Eclipse and Java for Total Beginners — Lesson 4, Syntax error, insert «;»)
| Syntax error, insert «;» to complete BlockStatements line 7 [message #1740731] | Wed, 17 August 2016 20:01 ![]() |
|
|
||
| I’m going thru tutorial, Eclipse and Java for Total Beginners — Lesson 4
Syntax error, insert «;» to complete BlockStatements line 7 /Totalbeginner/test/org/totalbeginner/tutorial/Persontest.java public class Persontest extends TestCase < public void testSetName() < public void testSetMaximumBooks() < line 7, /Totalbeginner/src/org/totalbeginner/tutorial/Person.java public class Person < //constructors public String getName() < public void setName(String name) < public int getMaximunBooks() < Источник |
Problem is that the eclipse recommendation makes little sense — to me. I checked my blocks several times.
This is my first time posting code so I’m hoping it’s formatted ok.
The eclipse error is on line 73: below the ; «anagrams.add(current);» This is the second line below the last for loop in the code.
package anagrecur2;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.io.*;
public class AnagRecur2Main {
public static void main(String[] args) {
List<String> anagrams = new ArrayList<String>();
List<String> preString = new ArrayList<String>();
List<String> postString = new ArrayList<String>();
List<String> word = new ArrayList<String>();
word.add("t");
word.add("e");
word.add("a");
word.add("m");
preString.add("");
postString.add("");
String c;
String current;
}
ArrayList<String> getAnagrams (String word, String preString){
// remove the first occurrence of each
// character in preString from word and
// stores it in postString
}
ArrayList<String> removePreStringFromWord(List word){
ArrayList<String> postString;
ArrayList<String> preString;
for (int i = 0; i < preString.size(); i++) {
for (int j = 0; j < word.size(); j++) {
if (preString.get(i)== word.get(j)){
word.remove(j);
}else {
postString.add((String) word.get(j));
}
}
return postString;
}
}
// using a string as if it is a c# string.
// for java you need to convert the string to
// char array
//ArrayList<String> word;
//String current;
//char poststrCharA;
ArrayList<String> anagrams;
ArrayList<String> preString;
ArrayList<String> postString;
String[] prestrAr = new String[preString.size()];{
prestrAr = preString.toArray(prestrAr);
for(String s : prestrAr){
System.out.println(s);
}
for (String poststrCharA : postString){
poststrCharA.toCharArray();
System.out.println("postStringtoCharAr"+poststrCharA);
}
// adds string combo to anagrams if
// it is a true word
for (String c : prestrAr) {
String current = prestrAr + c;
anagrams.add(current);
}
void getAnagrams(char word, char current){
System.out.println("word= "+word+"current= "+current);
}
}
Problem is that the eclipse recommendation makes little sense — to me. I checked my blocks several times.
This is my first time posting code so I’m hoping it’s formatted ok.
The eclipse error is on line 73: below the ; «anagrams.add(current);» This is the second line below the last for loop in the code.
package anagrecur2;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.io.*;
public class AnagRecur2Main {
public static void main(String[] args) {
List<String> anagrams = new ArrayList<String>();
List<String> preString = new ArrayList<String>();
List<String> postString = new ArrayList<String>();
List<String> word = new ArrayList<String>();
word.add("t");
word.add("e");
word.add("a");
word.add("m");
preString.add("");
postString.add("");
String c;
String current;
}
ArrayList<String> getAnagrams (String word, String preString){
// remove the first occurrence of each
// character in preString from word and
// stores it in postString
}
ArrayList<String> removePreStringFromWord(List word){
ArrayList<String> postString;
ArrayList<String> preString;
for (int i = 0; i < preString.size(); i++) {
for (int j = 0; j < word.size(); j++) {
if (preString.get(i)== word.get(j)){
word.remove(j);
}else {
postString.add((String) word.get(j));
}
}
return postString;
}
}
// using a string as if it is a c# string.
// for java you need to convert the string to
// char array
//ArrayList<String> word;
//String current;
//char poststrCharA;
ArrayList<String> anagrams;
ArrayList<String> preString;
ArrayList<String> postString;
String[] prestrAr = new String[preString.size()];{
prestrAr = preString.toArray(prestrAr);
for(String s : prestrAr){
System.out.println(s);
}
for (String poststrCharA : postString){
poststrCharA.toCharArray();
System.out.println("postStringtoCharAr"+poststrCharA);
}
// adds string combo to anagrams if
// it is a true word
for (String c : prestrAr) {
String current = prestrAr + c;
anagrams.add(current);
}
void getAnagrams(char word, char current){
System.out.println("word= "+word+"current= "+current);
}
}

Terry Huckaba