Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java compile error: "reached end of file while parsing }"

I have the following source code

public class mod_MyMod extends BaseMod
public String Version()
{
     return "1.2_02";
}
public void AddRecipes(CraftingManager recipes)
{
   recipes.addRecipe(new ItemStack(Item.diamond), new Object[] {
      "#", Character.valueOf('#'), Block.dirt
   });
}

When I try to compile it I get the following error:

java:11: reached end of file while parsing }

What am I doing wrong? Any help appreciated.

like image 293
adeo8 Avatar asked Feb 08 '11 14:02

adeo8


People also ask

What does Reached end of file while parsing mean in Java?

The error Reached End of File While Parsing is a compiler error and almost always means that your curly parenthesis are not ending completely or maybe there could be extra parenthesis in the end.

What character is missing to debug the error reached end of file while parsing?

This error occurs if a closing curly bracket i.e "}" is missing for a block of code (e.g method, class).

What is illegal start of type error in Java?

Missing braces According to Java syntax, every block has to start and end with an opening and a closing curly brace, respectively. If a brace is omitted, the compiler won't be able to identify the start and/or the end of a block, which will result in an illegal start of expression error (Fig. 4(a)).

What is else without if error?

'else' without 'if' This error means that Java is unable to find an if statement associated to your else statement. Else statements do not work unless they are associated with an if statement. Ensure that you have an if statement and that your else statement isn't nested within your if statement.


2 Answers

You have to open and close your class with { ... } like:

public class mod_MyMod extends BaseMod
{
  public String Version()
  {
    return "1.2_02";
  }

  public void AddRecipes(CraftingManager recipes)
  {
     recipes.addRecipe(new ItemStack(Item.diamond), new Object[] {
        "#", Character.valueOf('#'), Block.dirt });
  }
}
like image 126
Bigbohne Avatar answered Oct 14 '22 15:10

Bigbohne


You need to enclose your class in { and }. A few extra pointers: According to the Java coding conventions, you should

  • Put your { on the same line as the method declaration:
  • Name your classes using CamelCase (with initial capital letter)
  • Name your methods using camelCase (with small initial letter)

Here's how I would write it:

public class ModMyMod extends BaseMod {

    public String version() {
         return "1.2_02";
    }

    public void addRecipes(CraftingManager recipes) {
       recipes.addRecipe(new ItemStack(Item.diamond), new Object[] {
          "#", Character.valueOf('#'), Block.dirt
       });
    }
}
like image 20
aioobe Avatar answered Oct 14 '22 13:10

aioobe