问题
I am very new to coding and I keep getting this error I really need help with it. This is my code:
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
if (stack.getItem() == halo.TitaniumHelmet || stack.getItem() == halo.TitaniumChestplate || stack.getItem() == halo.TitaniumBoots) {
return "halo:textures/models/armor/Titanium1.png";
}
if (stack.getItem() == halo.TitaniumLeggings); {
return "halo:textures/models/armor/Titanium_layar_2.png";
} else { //<------ Syntax error on token "else", delete this token
return null;
}
回答1:
Here there is an extra semicolon after the condition:
if (stack.getItem() == halo.TitaniumLeggings);
Remove it. Statement will be like this:
if (stack.getItem() == halo.TitaniumLeggings) { ... }
回答2:
Change
if (stack.getItem() == halo.TitaniumLeggings); {
to
if (stack.getItem() == halo.TitaniumLeggings) {
This is bad, because
if (stack.getItem() == halo.TitaniumLeggings); {
//do stuff...
}
is equivalent to
if (stack.getItem() == halo.TitaniumLeggings) {
}
//The above EMPTY block is only executed when the
//if evaluates to true. The below is ALWAYS executed.
{
//do stuff
}
And that is bad.
回答3:
There is a ;
at a wrong place IMHO
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
if (stack.getItem() == halo.TitaniumHelmet || stack.getItem() == halo.TitaniumChestplate || stack.getItem() == halo.TitaniumBoots) {
return "halo:textures/models/armor/Titanium1.png";
}
if (stack.getItem() == halo.TitaniumLeggings) {
return "halo:textures/models/armor/Titanium_layar_2.png";
} else { //<------ Syntax error on token "else", delete this token
return null; }
Should work. Don't put ;
at if
-statements ;)
来源:https://stackoverflow.com/questions/22746317/syntax-error-on-token-else