Whats wrong with my java code? I really need help!
So i was working on my code for a game called Minecraft and so here is my first code, titled mod_MOO.java.
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
public static final Block MOOBlock = new MOO(123, ModLoader.addOverride("/terrain.png", "/MOO/MOOBlock.png").setHardness(2F).setResistance(1F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO");
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
And now here is MOO.java:
Code :
package net.minecraft.src;
public class MOOBlock extends Block
{
public MOOBlock(int i, int j)
{
super(i, j, Material.rock);
}
}
The error is on mod_MOO.java, it says on eclipse that the line with all of the properties and ids that it is missing two )'s.
Please help!!!
Re: Whats wrong with my java code? I really need help!
Please copy and paste here the full text of the error messages that you get from the compiler.
Some editors have tools for finding the ending char of an pair of () or {}.
Put the cursor on the leading ( or { and press a key combo to find the pairing ) or }.
In my editor its ctrl+ ]
Start on the inside and work outwards to find where there is a missing one.
Re: Whats wrong with my java code? I really need help!
Quote:
Please copy and paste here the full text of the error messages that you get from the compiler.
heres what it says on eclipse in the console thing when I run it:
Code :
27 achievements
174 recipes
ModLoader 1.1 Initializing...
Failed to load mod from "mod_MOO.class"
Done.
Loading: net.java.games.input.OSXEnvironmentPlugin
Starting up SoundSystem...
Initializing LWJGL OpenAL
(The LWJGL binding of OpenAL. For more information, see http://www.lwjgl.org)
OpenAL initialized.
And heres what it says in Minecraft (when it crashes):
Code :
Mods loaded: 1
ModLoader 1.1
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem.
If you wish to report this, please copy this entire text and email it to support@mojang.com.
Please include a description of what you did when the error occured.
--- BEGIN ERROR REPORT 9c4f49b2 --------
Generated 2/18/12 7:04 AM
Minecraft: Minecraft 1.1
OS: Mac OS X (x86_64) version 10.6.8
Java: 1.6.0_29, Apple Inc.
VM: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Apple Inc.
LWJGL: 2.4.2
OpenGL: NVIDIA GeForce 9400M OpenGL Engine version 2.1 NVIDIA-1.6.36, NVIDIA Corporation
java.lang.Error: Unresolved compilation problem:
Syntax error, insert ")" to complete VariableInitializer
at net.minecraft.src.mod_MOO.<init>(mod_MOO.java:5)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at net.minecraft.src.ModLoader.addMod(ModLoader.java:234)
at net.minecraft.src.ModLoader.readFromClassPath(ModLoader.java:1217)
at net.minecraft.src.ModLoader.init(ModLoader.java:708)
at net.minecraft.src.ModLoader.AddAllRenderers(ModLoader.java:150)
at net.minecraft.src.RenderManager.<init>(RenderManager.java:78)
at net.minecraft.src.RenderManager.<clinit>(RenderManager.java:9)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:316)
at net.minecraft.client.Minecraft.run(Minecraft.java:620)
at java.lang.Thread.run(Thread.java:680)
--- END ERROR REPORT 59e591c3 ----------
And also, I cant seem to find any command (im using a mac and eclipse)
Re: Whats wrong with my java code? I really need help!
If your editor does not have the pair finding tool, you can use your eyeballs.
Edit the line in question and put each section up to an ending ) on a line by itself and scan the lines for the correct pairing. Put the crusor after a ) and press Enter to move to a new line
An example line:
.setHardness(2F)
Then scan the lines and pair the ( with their ending )s
Re: Whats wrong with my java code? I really need help!
I've found that the parenthesis after "MOO" is underlined red, and the one matching with it (before "MOO") is not underlined, so now I am just confused.
Please don't get too complicated, Im very new to java
Re: Whats wrong with my java code? I really need help!
This is not complicated. You need to find where the missing ) is. Starting on the left find a ( and then move to the right end and find its pairing ).
Break your long statement up into a bunch of smaller simpler statements instead of trying to do it all in one statement.
For example:
<type1> var1 = <value for var1>
<type2> var2 = <value for var2>
public static final Block MOOBlock = new MOO(var1, var2) ;
If this is too complicated, print the program on a piece of paper and use a pencil to circle the ( and draw a line to the ending ) and circle it and connect the two. Continue until all (s are paired with a ).
Re: Whats wrong with my java code? I really need help!
for the "new MOO(123," there is no closing parenthesis, but everywhere I try on that line will give me another error.
Otherwise, everything matches up!
Re: Whats wrong with my java code? I really need help!
Quote:
for the "new MOO(123," there is no closing parenthesis
Add the ending ) at the just before the ;
Break the statement up into several short simple statements like I suggested before.
Re: Whats wrong with my java code? I really need help!
Quote:
Add the ending ) at the just before the ;
What it already is: setBlockName("MOO"); and when i do this: setBlockName("MOO")); basically the whole line goes crazy
I separated each property thing into its own separate line, and it still says (on .setBlockName) theres an error
heres my whole thing now:
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
public static final Block MOOBlock = new MOO(120,
ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png"),
setHardness(2F),
setResistance(1F),
setStepSound(Block.soundStoneFootstep),
setBlockName("MOO");
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
NOTE: it says this in the line with the setBlockName thing:
Code :
Multiple markers at this line
- Syntax error, insert ")" to complete
VariableInitializer
And again, the ) next to "MOO" is underlined red
Re: Whats wrong with my java code? I really need help!
The chained code that you wrote used .s to connect the value returned by one method to connect to the next method. You have left them out when you put the method calls on separate lines. Put the .s back where they go.
Where did you copy this statement from? It is a classical example of how to confuse beginners.
Go back to where you copied the statement from and copy it again.
Re: Whats wrong with my java code? I really need help!
this is what i was supposed to type(replacing some things with MOO and MOOBlock):
Code :
public static final Block oreTitanium = new CamelOreBlockOre(123, ModLoader.addOverride("/terrain.png", "/CamelMod/CamelOre/terrain/titaniumore.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("oreTitanium");
and now this is what mine says:
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
public static final Block MOOBlock= new MOO(123, ModLoader.addOverride("/terrain.png", "/MOO/MOOBlock.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO");
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
yet it still gives an error on that same line on that same closing parenthesis
Code :
Multiple markers at this line
- Syntax error, insert ")" to complete
VariableInitializer
- Syntax error, insert ")" to complete
VariableInitializer
Re: Whats wrong with my java code? I really need help!
Simplify your code removing the following from the constructor call.
Quote:
.setHardness(3F).setResistance(5F).setStepSound(Bl ock.soundStoneFootstep).setBlockName("MOO")
Do those method calls one by one.
Re: Whats wrong with my java code? I really need help!
Quote:
Originally Posted by
Norm
Simplify your code removing the following from the constructor call.
Do those method calls one by one.
like this?
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
public static final Block MOOBlock = new MOO(123, ModLoader.addOverride("/terrain.png", "/MOO/MOOBlock.png")
.setHardness(3F)
.setResistance(5F)
.setStepSound(Block.soundStoneFootstep)
.setBlockName("MOO");
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
because theres still errors
Re: Whats wrong with my java code? I really need help!
can you try this with eclipse and see if it gives you an error? Or will that not work?
Re: Whats wrong with my java code? I really need help!
What parameters does the MOO class's constructor take?
Code the call to that constructor with single variables for each parameter. Remove all the rest of the method calls from the constructor.
For example:
Code :
public static final Block MOOBlock = new MOO(123, <a variable here>);
Then before the constructor, define a variable for <a variable here> and use it in the constructor call above.
Re: Whats wrong with my java code? I really need help!
Quote:
Originally Posted by
Norm
What parameters does the MOO class's constructor take?
Code the call to that constructor with single variables for each parameter. Remove all the rest of the method calls from the constructor.
For example:
Code :
public static final Block MOOBlock = new MOO(123, <a variable here>);
Then before the constructor, define a variable for <a variable here> and use it in the constructor call above.
So heres my new mod_MOO:
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
public static final Block MOOBlock = new MOO(123, ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO"));
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
Now it has
Code :
ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F)
underlined red and the reason:
"
Cannot invoke setHardness(float) on the primitive type
int
"
And heres my MOO.java, if you need it:
Code :
package net.minecraft.src;
public class MOO extends Block
{
public MOO(int i, int j)
{
super(i, j, Material.rock);
}
}
Re: Whats wrong with my java code? I really need help!
If the MOO constructor takes 2 int variables, Change the code to something like this:
Code :
int secParm = ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO");
public static final Block MOOBlock = new MOO(123, secParm);
Then fix the value of secParm to be valid for the compile.
Re: Whats wrong with my java code? I really need help!
Quote:
Originally Posted by
Norm
If the MOO constructor takes 2 int variables, Change the code to something like this:
Code :
int secParm = ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO");
public static final Block MOOBlock = new MOO(123, secParm);
Then fix the value of secParm to be valid for the compile.
Now heres what it says:
Code :
Cannot invoke setHardness(float) on the primitive type int
and my code:
Code :
package net.minecraft.src;
public class mod_MOO extends BaseMod
{
static int MOOthing = ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F).setResistance(5F).setStepSound(Block.soundStoneFootstep).setBlockName("MOO");
public static final Block MOOBlock = new MOO(123, MOOthing);
public mod_MOO()
{
}
public void load()
{
ModLoader.RegisterBlock(MOOBlock);
ModLoader.AddName(MOOBlock, "MOO");
ModLoader.AddShapelessRecipe(new ItemStack(MOOBlock, 123), new Object[] {Item.leather, Item.leather});
}
public String getVersion()
{
return "1.0.0";
}
}
and the underlined red thing is this:
Code :
ModLoader.addOverride("/terrain.png","/MOO/MOOBlock.png").setHardness(3F)
Re: Whats wrong with my java code? I really need help!
You need to read the documentation for all the methods in that statement and see what they do, what values they return etc.
As I said before you need to break that chain of method calls up into single statements. Something like this:
<datatype> val = <objectRef>.<the method>(<the methods args>);
Where you replace the values in <>with the values from the chained statement being broken up.