好吧,所以我只是一个简单的菜鸟,试图在已有的代码上加上我自己的小麻烦。唯一的问题是我需要将.java文件转换为.class。我在使用eclipse时遇到了困难,因为我需要某些软件包以使一切正常工作,但是当我将软件包放在那里时,它就不会构建一般。所以我放弃了eclipse并尝试了javac命令提示符。当我尝试它时,它给了我这个对我没有意义的错误,我只是愚蠢还是javac无法正常工作?
导致错误的原因是:
EnumPokemon.java:36: error: illegal start of expression
for (EnumPokemon pokemon : ) {
^
EnumPokemon.java:46: error: illegal start of expression
for (EnumPokemon e : ) {
^
EnumPokemon.java:71: error: illegal start of expression
for (EnumPokemon e : ) {
^
EnumPokemon.java:97: error: illegal start of expression
for (EnumPokemon pokemon : ) {
如果有人可以帮助像我这样的简单的菜鸟,那将非常感激!
编辑:感谢您推荐编辑,我是java和本网站的新手,所以我不知道该怎么做。我会复制并粘贴代码RN
package com.pixelmonmod.pixelmon.enums;
import com.pixelmonmod.pixelmon.database.DatabaseHelper;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public enum EnumPokemon
{
Abra("Abra"), Absol("Absol"), Aerodactyl("Aerodactyl"), Aggron("Aggron"), Aipom("Aipom"), Alakazam("Alakazam"), Altaria("Altaria"), Ampharos("Ampharos"), Anorith("Anorith"), Arbok("Arbok"), Arcanine("Arcanine"), Arceus("Arceus"), Archen("Archen"), Archeops("Archeops"), Ariados("Ariados"), Armaldo("Armaldo"), Aron("Aron"), Articuno("Articuno"), Azumarill("Azumarill"), Bagon("Bagon"), Bastiodon("Bastiodon"), Bayleef("Bayleef"), Beedrill("Beedrill"), Beldum("Beldum"), Bellossom("Bellossom"), Bellsprout("Bellsprout"), Bisharp("Bisharp"), Blastoise("Blastoise"), Blaziken("Blaziken"), Blissey("Blissey"), Boldore("Boldore"), Braviary("Braviary"), Bulbasaur("Bulbasaur"), Butterfree("Butterfree"), Camerupt("Camerupt"), Carracosta("Carracosta"), Carvanha("Carvanha"), Caterpie("Caterpie"), Celebi("Celebi"), Chandelure("Chandelure"), Chansey("Chansey"), Charizard("Charizard"), Charmander("Charmander"), Charmeleon("Charmeleon"), Chatot("Chatot"), Chikorita("Chikorita"), Chimchar("Chimchar"), Chinchou("Chinchou"), Clefable("Clefable"), Clefairy("Clefairy"), Cleffa("Cleffa"), Cloyster("Cloyster"), Cottonee("Cottonee"), Cranidos("Cranidos"), Crobat("Crobat"), Croconaw("Croconaw"), Crustle("Crustle"), Combusken("Combusken"), Corphish("Corphish"), Corsola("Corsola"), Cryogonal("Cryogonal"), Cubone("Cubone"), Crawdaunt("Crawdaunt"), Cyndaquil("Cyndaquil"), Delibird("Delibird"), Dewott("Dewott"), Dewgong("Dewgong"), Diglett("Diglett"), Ditto("Ditto"), Dodrio("Dodrio"), Doduo("Doduo"), Donphan("Donphan"), Dragonair("Dragonair"), Dragonite("Dragonite"), Drapion("Drapion"), Dratini("Dratini"), Drifblim("Drifblim"), Drifloon("Drifloon"), Drowzee("Drowzee"), Dugtrio("Dugtrio"), Dunsparce("Dunsparce"), Duosion("Duosion"), Dwebble("Dwebble"), Eevee("Eevee"), Ekans("Ekans"), Electabuzz("Electabuzz"), Electivire("Electivire"), Electrode("Electrode"), Elekid("Elekid"), Emboar("Emboar"), Emolga("Emolga"), Empoleon("Empoleon"), Entei("Entei"), Espeon("Espeon"), Exeggcute("Exeggcute"), Exeggutor("Exeggutor"), Farfetchd("Farfetchd"), Fearow("Fearow"), Feraligatr("Feraligatr"), Flaaffy("Flaaffy"), Flareon("Flareon"), Flygon("Flygon"), Forretress("Forretress"), Galvantula("Galvantula"), Gastly("Gastly"), Gengar("Gengar"), Gigalith("Gigalith"), Girafarig("Girafarig"), Geodude("Geodude"), Glaceon("Glaceon"), Gligar("Gligar"), Gliscor("Gliscor"), Gloom("Gloom"), Golbat("Golbat"), Goldeen("Goldeen"), Golduck("Golduck"), Golem("Golem"), Golett("Golett"), Golurk("Golurk"), Graveler("Graveler"), Grimer("Grimer"), Grotle("Grotle"), Groudon("Groudon"), Grovyle("Grovyle"), Growlithe("Growlithe"), Gyarados("Gyarados"), Haunter("Haunter"), Hitmonchan("Hitmonchan"), Hitmonlee("Hitmonlee"), Hitmontop("Hitmontop"), Honchkrow("Honchkrow"), Hoothoot("Hoothoot"), Houndoom("Houndoom"), Houndour("Houndour"), Horsea("Horsea"), Hypno("Hypno"), Igglybuff("Igglybuff"), Infernape("Infernape"), Ivysaur("Ivysaur"), Jigglypuff("Jigglypuff"), Jolteon("Jolteon"), Joltik("Joltik"), Jynx("Jynx"), Kabuto("Kabuto"), Kadabra("Kadabra"), Kabutops("Kabutops"), Kakuna("Kakuna"), Kangaskhan("Kangaskhan"), Kingdra("Kingdra"), Kingler("Kingler"), Klang("Klang"), Klink("Klink"), Klinklang("Klinklang"), Koffing("Koffing"), Krabby("Krabby"), Krokorok("Krokorok"), Krookodile("Krookodile"), Kyogre("Kyogre"), Lairon("Lairon"), Lampent("Lampent"), Lanturn("Lanturn"), Lapra
s("Lapras"), Larvesta("Larvesta"), Larvitar("Larvitar"), Leafeon("Leafeon"), Leavanny("Leavanny"), Ledyba("Ledyba"), Ledian("Ledian"), Lickitung("Lickitung"), Litwick("Litwick"), Lugia("Lugia"), Lucario("Lucario"), Lunatone("Lunatone"), Luxio("Luxio"), Luxray("Luxray"), Machamp("Machamp"), Machoke("Machoke"), Machop("Machop"), Magby("Magby"), Magikarp("Magikarp"), Magmar("Magmar"), Magmortar("Magmortar"), Magnemite("Magnemite"), Magneton("Magneton"), Magnezone("Magnezone"), Mamoswine("Mamoswine"), Mankey("Mankey"), Mantine("Mantine"), Mareep("Mareep"), Marill("Marill"), Marowak("Marowak"), Marshtomp("Marshtomp"), Meganium("Meganium"), Meowth("Meowth"), Metagross("Metagross"), Metang("Metang"), Metapod("Metapod"), Mew("Mew"), Mewtwo("Mewtwo"), Miltank("Miltank"), Minun("Minun"), Misdreavus("Misdreavus"), Mismagius("Mismagius"), Moltres("Moltres"), Monferno("Monferno"), MrMime("MrMime"), Mudkip("Mudkip"), Muk("Muk"), Munchlax("Munchlax"), Murkrow("Murkrow"), Natu("Natu"), Nidoking("Nidoking"), Nidoqueen("Nidoqueen"), Nidoranfemale("Nidoranfemale"), Nidoranmale("Nidoranmale"), Nidorina("Nidorina"), Nidorino("Nidorino"), Ninetales("Ninetales"), Noctowl("Noctowl"), Numel("Numel"), Octillery("Octillery"), Oddish("Oddish"), Omanyte("Omanyte"), Omastar("Omastar"), Onix("Onix"), Oshawott("Oshawott"), Pachirisu("Pachirisu"), Paras("Paras"), Parasect("Parasect"), Pawniard("Pawniard"), Persian("Persian"), Phanpy("Phanpy"), Pichu("Pichu"), Pidgey("Pidgey"), Pikachu("Pikachu"), Pidgeotto("Pidgeotto"), Pidgeot("Pidgeot"), Pignite("Pignite"), Piloswine("Piloswine"), Pineco("Pineco"), Pinsir("Pinsir"), Piplup("Piplup"), Plusle("Plusle"), Politoed("Politoed"), Poliwag("Poliwag"), Poliwhirl("Poliwhirl"), Poliwrath("Poliwrath"), Ponyta("Ponyta"), Porygon("Porygon"), PorygonZ("Porygon-Z"), Porygon2("Porygon2"), Primeape("Primeape"), Prinplup("Prinplup"), Psyduck("Psyduck"), Pupitar("Pupitar"), Quilava("Quilava"), Qwilfish("Qwilfish"), Raichu("Raichu"), Raikou("Raikou"), Rampardos("Rampardos"), Rapidash("Rapidash"), Raticate("Raticate"), Rattata("Rattata"), Rayquaza("Rayquaza"), Remoraid("Remoraid"), Reuniclus("Reuniclus"), Rhydon("Rhydon"), Rhyhorn("Rhyhorn"), Rhyperior("Rhyperior"), Riolu("Riolu"), Roggenrola("Roggenrola"), Rufflet("Rufflet"), Sableye("Sableye"), Salamence("Salamence"), Samurott("Samurott"), Sandile("Sandile"), Sandshrew("Sandshrew"), Sandslash("Sandslash"), Sceptile("Sceptile"), Scizor("Scizor"), Scolipede("Scolipede"), Scyther("Scyther"), Seadra("Seadra"), Seaking("Seaking"), Sealeo("Sealeo"), Seel("Seel"), Serperior("Serperior"), Servine("Servine"), Sewaddle("Sewaddle"), Sharpedo("Sharpedo"), Shelgon("Shelgon"), Shellder("Shellder"), Shieldon("Shieldon"), Shinx("Shinx"), Shuckle("Shuckle"), Sigilyph("Sigilyph"), Skarmory("Skarmory"), Skorupi("Skorupi"), Slowbro("Slowbro"), Slowking("Slowking"), Slowpoke("Slowpoke"), Smeargle("Smeargle"), Snivy("Snivy"), Sneasel("Sneasel"), Snorlax("Snorlax"), Solosis("Solosis"), Solrock("Solrock"), Spearow("Spearow"), Spheal("Spheal"), Spinarak("Spinarak"), Squirtle("Squirtle"), Stantler("Stantler"), Staraptor("Staraptor"), Staravia("Staravia"), Starly("Starly"), Staryu("Staryu"), Starmie("Starmie"), Suicune("Suicune"), Swablu("Swablu"), Swadloon("Swadloon"), Swampert("Swampert"), Swinub("Swinub"), Tangela("Tangela"), Tauros("Tauros"), Teddiursa("Teddiursa"), Tentacool("Tentacool"), Tentacruel("Tentacruel"), Tepig("Tepig"), Tirtouga("Tirtouga"), Torchic("Torchic"), Torterra("Torterra"), Totodile("Totodile"), Trapinch("Trapinch"), Treecko("Treecko"), Tropius("Tropius"), Turtwig("Turtwig"), Typhlosion("Typhlosion"), Tyranitar("Tyranitar"), Tyrogue("Tyrogue"), Umbreon("Umbreon"), Ursaring("Ursaring"), Vaporeon("Vaporeon"), Venipede("Venipede"), Venomoth("Venomoth"), Venonat("Venonat"), Venusaur("Venusaur"), Vibrava("Vibrava"), Victreebel("Victreebel"), Vileplume("Vileplume"), Volcarona("Volcarona"), Voltorb("Voltorb"), Vulpix("Vulpix"), Wailmer("Wailmer"), Wailord("Wailord"), Wartortle("Wartortle"), Walrein("Walrein"), Weavile("Weavile"), Weedle("Weedle"), Weepinbell("Weepinbell"), Weezing("Weezing"), Whimsicott("Whimsicott"), Whirlipede("Whirlipede"), Wigglytuff("Wigglytuff"), Wobbuffet("Wobbuffet"), Wynaut("Wynaut"), Xatu("Xatu"), Yanma("Yanma"), Yanmega("Yanmega"), Zapdos("Zapdos"), Zoroark("Zoroark"), Zorua("Zorua"), Zubat("Zubat");
public static ArrayList<String> legendaries = new ArrayList(Arrays.asList(new String[] { "Articuno", "Zapdos", "Moltres", "Mewtwo", "Mew", "Entei", "Raikou", "Suicune", "Ho-Oh", "Ho-oh", "HoOh", "Lugia", "Celebi", "Regirock", "Regice", "Registeel", "Latios", "Latias", "Groudon", "Kyogre", "Rayquaza", "Jirachi", "Deoxys", "Uxie", "Azelf", "Mesprit", "Dialga", "Palkia", "Giratina", "Cresselia", "Darkrai", "Manaphy", "Phione", "Heatran", "Regigigas", "Shaymin", "Arceus", "Victini", "Cobalion", "Terrakion", "Virizion", "Keldeo", "Thundurus", "Tornadus", "Landorus", "Zekrom", "Reshiram", "Kyurem", "Genesect", "Meloetta", "Xerneas", "Yveltal", "Zygarde" }));
public String name;
private EnumPokemon(String name)
{
this.name = name;
}
public static boolean hasPokemon(String name)
{
return getFromName(name) != null;
}
@Deprecated
public static EnumPokemon get(String name)
{
return getFromName(name);
}
public static boolean hasPokemonAnyCase(String name)
{
for (EnumPokemon pokemon : ) {
if (name.replace("-", "").equalsIgnoreCase(pokemon.name.replace("-", ""))) {
return true;
}
}
return false;
}
public static EnumPokemon contains(String containsString)
{
for (EnumPokemon e : ) {
if (containsString.replace("-", "").contains(e.name.replace("-", "").toLowerCase())) {
return e;
}
}
return null;
}
public static EnumPokemon getFromDBID(int id)
{
Connection con = DatabaseHelper.getConnection();
try
{
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("select * from PIXELMON where PIXELMONID=" + id);
if (rs.next()) {
return getFromName(rs.getString("PIXELMONFULLNAME"));
}
}
catch (Exception e) {}
return null;
}
public static EnumPokemon getFromOrdinal(int ordinal)
{
for (EnumPokemon e : ) {
if (e.ordinal() == ordinal) {
return e;
}
}
return null;
}
public static EnumPokemon randomPoke()
{
return randomPoke(true);
}
public static EnumPokemon randomPoke(boolean canBeLegendary)
{
int pick = new Random().nextInt(values().length);
if (!canBeLegendary) {
while (legendaries.contains(values()[pick].name)) {
pick = new Random().nextInt(values().length);
}
}
return values()[pick];
}
public static EnumPokemon getFromNameAnyCase(String name)
{
for (EnumPokemon pokemon : ) {
if (name.replace("-", "").equalsIgnoreCase(pokemon.name.replace("-", ""))) {
return pokemon;
}
}
return null;
}
public static EnumPokemon getFromName(String name)
{
EnumPokemon[] arrayOfEnumPokemon;
int i;
int j;
try
{
if (valueOf(name) != null) {
return valueOf(name);
}
}
catch (Exception e)
{
arrayOfEnumPokemon = values();i = arrayOfEnumPokemon.length;j = 0;
}
for (; j < i; j++)
{
EnumPokemon p = arrayOfEnumPokemon[j];
if (p.name.replace("-", "").equalsIgnoreCase(name.replace("-", ""))) {
return p;
}
}
return null;
}
}
编辑2:是否有第一个建议,但现在我还有其他6个错误。
C:\Users\Frank\eclipse-workspace\EnumPokemon\bin\com\pixelmonmod\pixelmon\enums>javac EnumPokemon.java
EnumPokemon.java:3: error: package com.pixelmonmod.pixelmon.database does not exist
import com.pixelmonmod.pixelmon.database.DatabaseHelper;
^
EnumPokemon.java:47: error: package e does not exist
if (containsString.replace("-", "").contains(e.name.replace("-", "").toLowerCase())) {
^
EnumPokemon.java:48: error: cannot find symbol
return e;
^
symbol: variable e
location: class EnumPokemon
EnumPokemon.java:56: error: cannot find symbol
Connection con = DatabaseHelper.getConnection();
^
symbol: variable DatabaseHelper
location: class EnumPokemon
EnumPokemon.java:72: error: cannot find symbol
if (e.ordinal() == ordinal) {
^
symbol: variable e
location: class EnumPokemon
EnumPokemon.java:73: error: cannot find symbol
return e;
^
symbol: variable e
location: class EnumPokemon
答案 0 :(得分:1)
以下代码在无效的Java代码中。您缺少for-loop
应该迭代的迭代器。
for (EnumPokemon pokemon : ) {
...
}
我假设您希望迭代EnumPokemon
的值,您的代码应如下所示。
for (EnumPokemon pokemon : EnumPokemon.values()) {
...
}