Results 1 to 5 of 5
  1. #1
    cjfshaw is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    skaterboy987 is offline Member
    Join Date
    Sep 2011
    Posts
    56
    Rep Power
    0

    Default 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!

  3. #3
    cjfshaw is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: Can't import my own class, getting a " ';' expected" error

    Got it mate.

    Java 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;
    	}
     }
    and the main file
    Java Code:
    import Champion;
    
    public class LoLSimulator {
    
        public static void main(String[] args) {
    
        	// TODO, add your application code
        	System.out.println("Hello World!");
        }
    }

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default 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;

  5. #5
    cjfshaw is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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.

    Java Code:
    public class LoLSimulator {
    
        public static void main(String[] args) {
    		Champion Ashe = new Champion();
    		int hp = Ashe.hp;
    		System.out.println("Ashe hp: " + hp);
        }
    }
    And the champion class, same as before but now with a default constructor
    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;
    	}
     }
    I'm trying to get it to print out a field of my 'Ashe' object but it isn't working.

Similar Threads

  1. Error - "The import org.junit cannot be resolved"
    By Jessaurum in forum New To Java
    Replies: 7
    Last Post: 11-03-2009, 03:20 AM
  2. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 12:19 AM
  3. Syntax error on token "(", ; expected
    By romilc in forum New To Java
    Replies: 7
    Last Post: 10-24-2009, 01:23 AM
  4. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  5. Replies: 3
    Last Post: 12-05-2008, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •