Jump to content

Small Syntax Error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Hello all,

This is probably a mistake I missed (I'm relativley new to Java) but this is what it says:
[SIZE=1] [/SIZE]
[LEFT]Multiple markers at this line
- Syntax error, insert "}" to complete 
ClassBody[/LEFT]
- Debug Current Instruction Pointer

The only thing on that line was a } at the end of the program!

Thanks to any help.

#2
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
Post your whole code so you can get a proper answer, but it seems you're lacking some brackets.

#3
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
It'll be because a bracket is missing, where it should be to close one part of your code. Like bobdark says, if you post all your code, we could find it more easily. However my advice would be just to check the amount of opening '{' and closing '}' and make sure they are the same.

#4
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
I'm a beginner, so basically it tests a number in the variable passCodeForLock if it is 15671 then it allows you to write to a text file (not complete so it hasn't got the text file thing). BTW How do you write to a text file in Java?

Thanks.

[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] java.util.Scanner;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Password_Lock {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] main(String[] args) {
Scanner passCodeForLock = [/SIZE][B][U][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (System.in);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] scrambledValue = passCodeForLock - 3 + 9;

System.out.println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Enter your assigned password:"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);


[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (passCodeForLock == 15671){
System.out.println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Access Granted..."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
System.out.println ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Access Denied"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}[/LEFT]
[U]}
[/U][/SIZE]


#5
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
You are missing a } at the end of your code. You need one to close the class, and one to close the Main() method.

Here is an example code for writing to a file:
try {
    BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
    out.write("aString");
    out.close();
} catch (IOException e) {
}

And here is the tutorial from Sun:
File Operations (The Java™ Tutorials > Essential Classes > Basic I/O)