Jump to content
  • Advertisement
Sign in to follow this  
boogyman19946

cannot find symbol even though its defined

This topic is 1860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello folks. It has been a while since I posted on the forums.

 

I've revived a project from ages ago, and I've been going through the source trying to get the thing to work. I'm getting the following errors:

 

E:\NetBeansProjects\Digestion\src\Entity\Entity.java:164: error: cannot find symbol
			mMotionModule.resetTimer();
			             ^
  symbol:   method resetTimer()
  location: variable mMotionModule of type MotionModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:173: error: cannot find symbol
			mMotionModule.update(this, manager.getEntities());
			             ^
  symbol:   method update(Entity,LinkedList<Entity>)
  location: variable mMotionModule of type MotionModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:176: error: cannot find symbol
			mPathfindingModule.update();
			                  ^
  symbol:   method update()
  location: variable mPathfindingModule of type PathfindingModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:189: error: cannot find symbol
			mHealthModule.draw(canvas);
			             ^
  symbol:   method draw(GameCanvas)
  location: variable mHealthModule of type HealthModule
4 errors
E:\NetBeansProjects\Digestion\nbproject\build-impl.xml:605: The following error occurred while executing this line:
E:\NetBeansProjects\Digestion\nbproject\build-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

 

I thought this was a rather routine error: I probably just misspelled a few function names. The thing is though, I haven't. To make extra sure, I copied and pasted them into place but the compiler still gives me those errors. Even more strange, NetBeans' error highlighter does not mark these lines as errors. Only the compiler. 

 

Here is the Entity class (errors are marked with line comments)

package Entity;

import java.awt.geom.Rectangle2D;

import Core.Level.Level;
import Core.Messages.Message;
import Core.Messages.MessageQueue;
import Entity.EntityScripting.EntityScript;
import Entity.Modules.*;
import Graphics.GameCanvas;

public class Entity {
	private String mName;
	private Rectangle2D.Float mBoundRect;
	private int mDepth;
	
	private Level mLevel;
	
	private String m_pwd;
	private EntityScript mObjectScript;

	private HealthModule mHealthModule;
	private MotionModule mMotionModule;
	private GraphicsModule mGraphicsModule;
	private SoundModule mSoundModule;
	private PathfindingModule mPathfindingModule;
	
	private MessageQueue mMessageQueue;

	public Entity(Level level) {
		mLevel = level;
		mName = "Default";
		mBoundRect = new Rectangle2D.Float(0, 0, 0, 0);
		m_pwd = null;  
		mObjectScript = null;
		
		mHealthModule = null;
		mMotionModule = null;
		mGraphicsModule = null;
		mPathfindingModule = null;
		mSoundModule = null;
		
		mMessageQueue = new MessageQueue();
	}

	public boolean initialize(String pwd, EntityScript objectScript, int x, int y, String[] arguments) {
		m_pwd = pwd;
		mObjectScript = objectScript;
		
		mBoundRect.x = x;
		mBoundRect.y = y;
		
		mObjectScript.create(this, arguments);
		
		return true;
	}
     
        // ...
        // Snip unrelated functions
        // ...

	public void reset() {
		if(mMotionModule != null)
			mMotionModule.resetTimer();                        // Error occurs here
		
		mObjectScript.reset();
	}
	
	public void update(EntityManager manager) {
		processMessages();
		
		if(mMotionModule != null)
			mMotionModule.update(this, manager.getEntities()); // Error occurs here
		
		if(mPathfindingModule != null)
			mPathfindingModule.update();                       // Error occurs here
		
		mObjectScript.processKeys();
		mObjectScript.update();
	}
	
	public void draw(GameCanvas canvas) {
		if(mGraphicsModule != null) {
			mGraphicsModule.draw(canvas);
			mObjectScript.draw();
		}
		
		if(mHealthModule != null) {
			mHealthModule.draw(canvas);                        // Error occurs here
		}
	}
}

 

 

and the MotionModule class (the error is the same for the other two classes featuring different functions)

 

package Entity.Modules;

import java.awt.geom.*;
import java.util.LinkedList;

import Entity.Entity;
import Util.GameTimer;
import Util.Vector2D;

public class MotionModule {
	private static class Force	{
		String name;
		Vector2D force;
		
		public Force(String name, Vector2D force) {
			this.name = name;
			this.force = force;
		}
	}

	private double mMass;
	
	private Vector2D mVelocity;
	private double mTerminalVelocity;
	
	private LinkedList<Force> mForces;
	
	private Vector2D mJumpForce;
	private boolean mJump;
	private boolean mCanJump;
	private boolean mCanDoubleJump;
	private boolean mDoubleJumpFlag;
	
	private boolean mStopOnSolid;
	private double mGravity;
	
	private GameTimer mTimer;
	
	//////////////////////
	// PUBLIC INTERFACE //
	//////////////////////	
	public MotionModule(double mass, double terminalVelocity) {
		mMass = mass;
		
		mVelocity = new Vector2D(0.0f, 0.0f);
		mTerminalVelocity = terminalVelocity;
		
		mForces = new LinkedList<Force>();
		
		mJumpForce = new Vector2D(0.0, 0.0);
		mJump = false;
		mDoubleJumpFlag = false;
		
		mStopOnSolid = false;
		mGravity = 0.0;
		
		mTimer = new GameTimer();
	}

        // ...
        // Snip unrelated functions
        // ...

	public void resetTimer() {
		mTimer.reset();
	}
	
	public void update(Entity entity, LinkedList<Entity> entityList) {
		// Elapsed time in seconds
		double elapsedTime = getTimeStep();
		
		Rectangle2D.Float entRect = entity.getObjectRect();
		
		//////////////////
		// Move forward //
		//////////////////
		Vector2D deltaPos = integrateVelocity(elapsedTime);
		
		entRect.x += deltaPos.x;
		entRect.y += deltaPos.y;
		
		/////////////////////
		// Check collision //
		/////////////////////
		Entity obstacle = null;
		boolean collisionFree = false;
		while(!collisionFree) {
			for(Entity worldEntity: entityList) {
				if(!entRect.intersects(worldEntity.getObjectRect()))
					continue;

				Rectangle2D.Float obstRect = worldEntity.getObjectRect();

				Vector2D entCenter = new Vector2D(entRect.x + entRect.width/2, entRect.y + entRect.height/2);
				Vector2D obstCenter = new Vector2D(obstRect.x + obstRect.width/2, obstRect.y + obstRect.height/2);

				Vector2D obstClosestCorner = closestCornerToCenter(entCenter, obstRect);
				Vector2D entClosestCorner = closestCornerToCenter(obstCenter, entRect);

				Vector2D posShift = obstClosestCorner.subtract(entClosestCorner).projectOn(deltaPos);

				entClosestCorner = entClosestCorner.subtract(posShift);

				Vector2D collisionNormal = getCollisionNormal(entClosestCorner, obstClosestCorner, deltaPos);
				

				entRect.x -= posShift.x;
				entRect.y -= posShift.y;
			}
			
			collisionFree = true;
		}
	}
}

 

 

The package hierarchy is as follows <src>/Entity/Modules

The Entity class resides in package Entity, whereas all the Modules reside in Entity/Modules

 

Does anyone have any idea as to why I'm getting this seemingly baseless error? Some folks said it has to do with classpaths. I looked through the project properties but I have not found anything that might cause this.

Share this post


Link to post
Share on other sites
Advertisement

Everything looks right.  If there is some simple typo or something, then don't feel bad because I don't see it either.  If I had to guess then there is a problem with the packages.  Maybe the folders are all lower case and don't start with a capital letter?  

 

Packages names and folders are all lower case by convention, but I do not know if Java actually cares.  I've never even tried.  If I were you, I would start a new project and create example files with the same packages names and see if that works.

Share this post


Link to post
Share on other sites

I had a feeling that it wasn't the code that was generating the error, and it seems I was right. To be extra sure I wasn't going crazy, I compiled the code manually via command line last night and it compiled without problem. To fix the problem, I copied all of the source code, deleted the project in NetBeans, created a new one, and pasted the source back into the right folder. Then NetBeans was able to compiled the source without goofy errors. I intended to post the fix yesterday night but for some reason I was not able to log in, so I'm only able to post the update today.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!