Results 1 to 5 of 5
- 10-20-2011, 03:44 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Can't import my own class, getting a " ';' expected" error
So, I'm using JCreator. I have a class that compiles no problem. However, when I create a new file to house my main method I get an error when I try to import the class.
Error: ';' expected
This error occurs twice at the line where I do my import. The thing is, if I look in the folder where these files are stored it all looks good. Both my main.java and my class.java are in the same folder, with their compiled counterparts in a separate folder (I didn't do this, it's just how JCreator organized these files for me when I made a project.). I have no idea why this isn't working. I've googled and searched this forum and others. It looks like the only thing I should need for this to work is to have the files be in the same folder and have import class at the top of my main file but that's not working.
- 10-20-2011, 03:50 AM #2
Member
- Join Date
- Sep 2011
- Posts
- 56
- Rep Power
- 0
Re: Can't import my own class, getting a " ';' expected" error
Please copy and paste your code into here using [.CODE] [./CODE] tags. Remove the dots first!
- 10-20-2011, 03:53 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Can't import my own class, getting a " ';' expected" error
Got it mate.
and the main fileJava Code:import java.util.*; //Need to account for level. public class Champion { //class fields, AKA champion stats public String NAME; //public String TITLE; //Commented out because of problems in file reading public int hp; public int HPGROWTH; public double hp5; public int mp; public int MPGROWTH; public double mp5; public double MP5GROWTH; public double atk_spd; public double ASGROWTH; public int dmg; public int DMGGROWTH; public int abil_pow; public int f_arm_pen; public int p_arm_pen; public int f_mag_pen; public int p_mag_pen; public double crit; public double critMod; public double armor; public double ARMORGROWTH; public double mr; public double MRGROWTH; public double dodge; public double lifesteal; public double spellvamp; public double tenacity; public double cdr; public int range; public double ms; //constructor: may need to replaye 'String title' after String name public Champion(String name, int hp, int hpgrowth, double hp5, int mp, int mpgrowth, double mp5, double mp5growth, double atk_spd, double asgrowth, int dmg, int dmggrowth, int abil_pow, int f_arm_pen, int p_arm_pen, int f_mag_pen, int p_mag_pen, double crit, double critmod, double armor, double armorgrowth, double mr, double mrgrowth, double dodge, double lifesteal, double spellvamp, double tenacity, double cdr, int range, double ms) { NAME = name; //TITLE = title; hp = hp; HPGROWTH = hpgrowth; hp5 = hp5; mp = mp; MPGROWTH = mpgrowth; mp5 = mp5; MP5GROWTH = mp5growth; atk_spd = atk_spd; ASGROWTH = asgrowth; dmg = dmg; DMGGROWTH = dmggrowth; abil_pow = abil_pow; f_arm_pen = f_arm_pen; p_arm_pen = p_arm_pen; f_mag_pen = f_mag_pen; p_mag_pen = p_mag_pen; crit = crit; critMod = critmod; armor = armor; ARMORGROWTH = armorgrowth; mr = mr; MRGROWTH = mrgrowth; dodge = dodge; lifesteal = lifesteal; spellvamp = spellvamp; tenacity = tenacity; cdr = cdr; range = range; ms = ms; } //methods, AKA functions for this class //need to include all the 'set' functions in here public void setHP(int hpUpdate) { hp = hp + hpUpdate; } public void setHP5(int hp5Update) { hp5 = hp5 + hp5Update; } public void setMP(int mpUpdate) { mp = mp + mpUpdate; } public void setmp5(int mp5Update) { mp5 = mp5 + mp5Update; } public void setAS(int asUpdate) { atk_spd = atk_spd + asUpdate; } public void setDMG(int dmgUpdate) { dmg = dmg + dmgUpdate; } public void setAP(int apUpdate) { abil_pow = abil_pow + apUpdate; } public void setFArmPen(int armpenUpdate) { f_arm_pen = armpenUpdate; } public void setPArmPen(int armpenUpdate) { p_arm_pen = armpenUpdate; } public void setFMagPen(int magpenUpdate) { f_mag_pen = magpenUpdate; } public void setPMagPen(int magpenUpdate) { f_mag_pen = magpenUpdate; } public void setCrit(int critUpdate) { crit = crit + critUpdate; } public void setCritMod(int critmodUpdate) { critMod = critMod + critmodUpdate; } public void setArm(int armUpdate) { armor = armor + armUpdate; } public void setMr(int mrUpdate) { mr = mr + mrUpdate; } public void setDodge(int dodgeUpdate) { dodge = dodge + dodgeUpdate; } public void setLifesteal(int lifestealUpdate) { lifesteal = lifesteal + lifestealUpdate; } public void setSpellvamp(int spellvampUpdate) { spellvamp = spellvamp + spellvampUpdate; } public void setTenacity(int tenacityUpdate) { tenacity = tenacity + tenacityUpdate; } public void setCDR(int cdrUpdate) { cdr = cdr + cdrUpdate; } public void setRange(int rangeUpdate) { range = range + rangeUpdate; } public void setMS(int msUpdate) { ms = ms + msUpdate; } }
Java Code:import Champion; public class LoLSimulator { public static void main(String[] args) { // TODO, add your application code System.out.println("Hello World!"); } }
- 10-20-2011, 04:07 AM #4
Re: Can't import my own class, getting a " ';' expected" error
Is Champion and LoLSimulator in the same package(directory)? If yes then you do not need to import Champion. If they are in different packages then you need use the full package name in the import statement.
Java Code:import full.package.name.Champion;
- 10-20-2011, 05:10 AM #5
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Can't import my own class, getting a " ';' expected" error
Hey so it looks like you were right Junky, because they were in the same folder I didn't need to import or anything, I can just use the Champion class. However, now although it compiles fine it doesn't seem to do anything. Below is what I'm using currently.
And the champion class, same as before but now with a default constructorJava Code:public class LoLSimulator { public static void main(String[] args) { Champion Ashe = new Champion(); int hp = Ashe.hp; System.out.println("Ashe hp: " + hp); } }
I'm trying to get it to print out a field of my 'Ashe' object but it isn't working.Java Code:/** * @(#)Champion.java * * * @author: Chris Shaw * @version 1.00 2011/10/14 * * This file contains the champion class. */ import java.util.*; //Need to account for level. public class Champion { //class fields, AKA champion stats public String NAME; //public String TITLE; //Commented out because of problems in file reading public int hp; public int HPGROWTH; public double hp5; public int mp; public int MPGROWTH; public double mp5; public double MP5GROWTH; public double atk_spd; public double ASGROWTH; public int dmg; public int DMGGROWTH; public int abil_pow; public int f_arm_pen; public int p_arm_pen; public int f_mag_pen; public int p_mag_pen; public double crit; public double critMod; public double armor; public double ARMORGROWTH; public double mr; public double MRGROWTH; public double dodge; public double lifesteal; public double spellvamp; public double tenacity; public double cdr; public int range; public double ms; //constructor: may need to replaye 'String title' after String name public Champion() { NAME = "name"; //TITLE = title; hp = 1; HPGROWTH = 1; hp5 = 1.0; mp = 1; MPGROWTH = 1; mp5 = 1.0; MP5GROWTH = 1.0; atk_spd = 1.0; ASGROWTH = 1.0; dmg = 1; DMGGROWTH = 1; abil_pow = 1; f_arm_pen = 1; p_arm_pen = 1; f_mag_pen = 1; p_mag_pen = 1; crit = 1.0; critMod = 1.0; armor = 1.0; ARMORGROWTH = 1.0; mr = 1.0; MRGROWTH = 1.0; dodge = 1.0; lifesteal = 1.0; spellvamp = 1.0; tenacity = 1.0; cdr = 1.0; range = 1; ms = 1.0; } public Champion(String name, int hp, int hpgrowth, double hp5, int mp, int mpgrowth, double mp5, double mp5growth, double atk_spd, double asgrowth, int dmg, int dmggrowth, int abil_pow, int f_arm_pen, int p_arm_pen, int f_mag_pen, int p_mag_pen, double crit, double critmod, double armor, double armorgrowth, double mr, double mrgrowth, double dodge, double lifesteal, double spellvamp, double tenacity, double cdr, int range, double ms) { NAME = name; //TITLE = title; hp = hp; HPGROWTH = hpgrowth; hp5 = hp5; mp = mp; MPGROWTH = mpgrowth; mp5 = mp5; MP5GROWTH = mp5growth; atk_spd = atk_spd; ASGROWTH = asgrowth; dmg = dmg; DMGGROWTH = dmggrowth; abil_pow = abil_pow; f_arm_pen = f_arm_pen; p_arm_pen = p_arm_pen; f_mag_pen = f_mag_pen; p_mag_pen = p_mag_pen; crit = crit; critMod = critmod; armor = armor; ARMORGROWTH = armorgrowth; mr = mr; MRGROWTH = mrgrowth; dodge = dodge; lifesteal = lifesteal; spellvamp = spellvamp; tenacity = tenacity; cdr = cdr; range = range; ms = ms; } //methods, AKA functions for this class //need to include all the 'set' functions in here public void setHP(int hpUpdate) { hp = hp + hpUpdate; } public void setHP5(int hp5Update) { hp5 = hp5 + hp5Update; } public void setMP(int mpUpdate) { mp = mp + mpUpdate; } public void setmp5(int mp5Update) { mp5 = mp5 + mp5Update; } public void setAS(int asUpdate) { atk_spd = atk_spd + asUpdate; } public void setDMG(int dmgUpdate) { dmg = dmg + dmgUpdate; } public void setAP(int apUpdate) { abil_pow = abil_pow + apUpdate; } public void setFArmPen(int armpenUpdate) { f_arm_pen = armpenUpdate; } public void setPArmPen(int armpenUpdate) { p_arm_pen = armpenUpdate; } public void setFMagPen(int magpenUpdate) { f_mag_pen = magpenUpdate; } public void setPMagPen(int magpenUpdate) { f_mag_pen = magpenUpdate; } public void setCrit(int critUpdate) { crit = crit + critUpdate; } public void setCritMod(int critmodUpdate) { critMod = critMod + critmodUpdate; } public void setArm(int armUpdate) { armor = armor + armUpdate; } public void setMr(int mrUpdate) { mr = mr + mrUpdate; } public void setDodge(int dodgeUpdate) { dodge = dodge + dodgeUpdate; } public void setLifesteal(int lifestealUpdate) { lifesteal = lifesteal + lifestealUpdate; } public void setSpellvamp(int spellvampUpdate) { spellvamp = spellvamp + spellvampUpdate; } public void setTenacity(int tenacityUpdate) { tenacity = tenacity + tenacityUpdate; } public void setCDR(int cdrUpdate) { cdr = cdr + cdrUpdate; } public void setRange(int rangeUpdate) { range = range + rangeUpdate; } public void setMS(int msUpdate) { ms = ms + msUpdate; } }
Similar Threads
-
Error - "The import org.junit cannot be resolved"
By Jessaurum in forum New To JavaReplies: 7Last Post: 11-03-2009, 03:20 AM -
Syntax error on token "(", ; expected
By baltimore in forum AWT / SwingReplies: 3Last Post: 10-28-2009, 12:19 AM -
Syntax error on token "(", ; expected
By romilc in forum New To JavaReplies: 7Last Post: 10-24-2009, 01:23 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM -
error"<identifier> expected" trough the use of interface
By parme in forum New To JavaReplies: 3Last Post: 12-05-2008, 08:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks