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.

1

4 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 }); }
}
1

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 }); }
}
2

It happens when you don't properly close the code block:

if (condition){ // your code goes here* { // This doesn't close the code block

Correct way:

if (condition){ // your code goes here
} // Close the code block
1

Yes. You were missing a '{' under the public class line. And then one at the end of your code to close it.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like