#What does You have a syntax error in your code: Unexpected token '}' means?

1 messages ยท Page 1 of 1 (latest)

mild moth
#

Help please ๐Ÿ˜ฆ

eager merlinBOT
#

<@&987246399047479336> please have a look, thanks.

eager merlinBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

In Java, the error message "You have a syntax error in your code: Unexpected token '}'" means that there is an issue with the placement or usage of a closing curly brace ('}').

This error typically occurs when there is an extra or missing closing curly brace in your code. Each opening curly brace ('{') should have a corresponding closing curly brace ('}') to define the scope of a block of code, such as a method, loop, or conditional statement.

To fix this error, you need to carefully review your code and ensure that all opening and closing curly braces are properly matched. Make sure that each opening brace has a corresponding closing brace and vice versa. Additionally, check for any misplaced or unnecessary braces.

Here's an example to illustrate the issue:

public class Example {
    public static void main(String[] args) {
        int x = 5;
        if (x > 0) {
            System.out.println("Positive number.");
        } // Missing closing brace for if statement
    } // Unexpected token '}' - extra closing brace
} // Unexpected token '}' - extra closing brace

In this example, there is a missing closing brace for the if statement and two extra closing braces at the end of the code. To fix it, you would need to add a closing brace after the System.out.println statement and remove the two extra braces at the end:

public class Example {
    public static void main(String[] args) {
        int x = 5;
        if (x > 0) {
            System.out.println("Positive number.");
        }
    }
}

By ensuring proper matching of opening and closing braces, you can resolve this syntax error.

grand sky
#

bruh first why does it say your code is indented properly

#

its not

mild moth
#

im new to programming

#

`public class Staircase extends SuperKarel
{
public void run()
{
putBall();
{
while(frontIsClear())
}
}
private void createStep()
{
turnRight();
putBall();

    while (frontIsClear())
    {
        move();
        putBall();
        turnLeft();
    }
    
}

}`

#

this is what i typed in

#

it was a mess and the indications for the excersice are just to ident

grand sky
#

it should be formatted like this:

public class Staircase extends SuperKarel {

    public void run() {
        putBall();
        // problem is here
        {
            while(frontIsClear())
        }
    }

    private void createStep() {
        turnRight();
        putBall();
        
        while (frontIsClear()) {
            move();
            putBall();
            turnLeft();
        }
    }

}
mild moth
#

OH

#

is it okay if I ask?

grand sky
#

and the problem that is telling you is your while loop and the { }

grand sky
mild moth
#

it says its wrong D:

grand sky
#

sorry but I need to say:
thats quite a shit "course" or whatever that is

mild moth
#

I wanted to ask for a propper identing info

#

idk if you got some video on yt or something to understand better

grand sky
#

to better learn java?

mild moth
#

yes

#

cuz im struggling hard with the CodeHS

grand sky
#

we usually recommend "mooc's" java course
its by a finnish university and really great
I went through it myself to learn java
and it gives you certificates at the end (not really important though)

eager merlinBOT
#

MOOC is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.

It consists of two parts, one at beginner, and another at intermediate level. The end of the course is marked by creating your own Asteroids game clone!

Even though the instructions show how to configure and use NetBeans for the course, you can use IntelliJ. To use IntelliJ, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.

Visit MOOC here: https://java-programming.mooc.fi/
(the course is available in both English and Finnish)

About the course - Java Programming

grand sky
#

some more information about it

mild moth
#

thank you so much

#

so there is no

#

kind of solution to my

#

code problem right?

grand sky
#

there is

#

but it tells you wrong formatting

#

the functionality problem its talking about is here:

    public void run() {
        putBall();
        // problem is here
        {
            while(frontIsClear())
        }
    }
mild moth
#

maybe i should tell the teacher right?

#

D:

grand sky
#

your teacher suggested you this course?

#

or its from him?

mild moth
#

its from him

#

to what I know

grand sky
#

๐Ÿ’€

mild moth
#

YEAH

#

i had problems before

#

idk why

#

lemme look up the email

grand sky
#
  • Open brace โ€œ{โ€ appears at the end of the same line as the declaration statement
  • Closing brace โ€œ}โ€ starts a line by itself indented to match its corresponding opening
    statement, except when it is a null statement the โ€œ}โ€ should appear immediately after the
    โ€œ{โ€œ
#

basically

public void method1() {
    System.out.println("Hello World!");
}

and if its empty

public void method2() {}
mild moth
#

its weird then

#

lemme message the school

#

tysm squid!!!

grand sky
#

no problem

mild moth
#

ill write down all the info you provided

grand sky
#

they should def. look up java style conventions

#

also maybe they got this wrong as well:

eager merlinBOT
#

The naming convention in Java is as follows:

Classes:
PascalCase. Example: GoldMiner, FoodDestroyer, DispenserBuilder

Methods / Fields / Variables:
camelCase. Example: foodAmount, integerValue, goodBoyAsADog

Packages:
All lowercase. Preferably the domain name backwards. Example: "google.com" ==> com.google, "ialistannen.me" ==> me.ialistannen
Followed by the project name. Example: Project "Builder" ==> com.google.builder

Constants/Enum entries:
UPPER_SNAKE_CASE. Where words are separated by underscores. Example: RED_DOG, I_AM_THE_BEST, CONQUER_WORLD

mild moth
#

yep

#

it wouldnt be the first time tbh

grand sky
#

conventions you should follow to make it easier for other devs to go through your code

#

sad that they teach it like this

#

so everyone new will just accept it and think it is right

mild moth
#

im abt to cry bc this is the next thing i have to do

naive copper
#

come on now, help karel find the ball

eager merlinBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘