Tuesday, 15 January 2013

java - Error while trying to return a value. -



java - Error while trying to return a value. -

i'm stuck on lastly part of homework. have homecoming agent value, reason maintain getting error saying "this method must homecoming type agent", though returning agent. help appreciated.

import java.io.file; import java.util.hashmap; import jeff.ini.ini; public class configloader { private ini _ini; private hashmap<string, space> _spaces = new hashmap<string, space>(); private hashmap<string, portal> _portals = new hashmap<string, portal>(); private hashmap<string, agent> _agents = new hashmap<string, agent>(); public configloader(file inifile) { _ini = new ini(inifile); } public agent buildall() { _buildspaces(); _buildportals(); _buildexits(); _builddestinations(); _buildagents(); homecoming _selectstartagent(); } private void _buildspaces(){ for(string spacename : _ini.keys("spaces")){ string descrip= _ini.get("spaces", spacename); string image= _ini.get("images", "images"); space space1= new space(spacename, descrip, image, null); _spaces.put(spacename, space1); } } private void _buildportals(){ for(string portalname : _ini.keys("portals")){ string descrip= _ini.get("portal", portalname); portal portal1=new portal(portalname, descrip, null); _portals.put(portalname, portal1); } } private void _buildexits(){ for(string spacename : _ini.keys("exits")){ string spaceexit = _ini.get("exits", spacename); space space = _spaces.get(spacename); portal exit = _portals.get(spaceexit); space.setportal(exit); } } private void _builddestinations(){ for(string portalname : _ini.keys("destinations")){ string destination = _ini.get("destinations", portalname); space des = _spaces.get(destination); if(des == null){ system.out.print("error"); system.exit(1); } else{ portal portal = _portals.get(portalname); portal.setdestination(des); } } } private void _buildagents(){ for(string agentname : _ini.keys("agents")){ string agent = _ini.get("agents" , agentname); space space = _spaces.get(agent); if(space == null){ system.out.print("error"); system.exit(1); } else{ agent = new agent(space, agentname); _agents.put(agentname, a); } } } private agent _selectstartagent(){ for(string agentname : _ini.keys("start")){ string agent = _ini.get("start" , agentname); agent agent1 = _agents.get(agent); if(agent == null){ system.out.print("error"); system.exit(1); } else{ homecoming agent1; } } } }

the key execution paths must homecoming value of type agent, null. calling method must, usual, check whether returned value null.

now let's @ missing:

the if branch not homecoming value, instead abruptly exits. if for loop never entered, method not homecoming either.

with fixed, entire code like:

for (string agentname : _ini.keys("start")){ string agent = _ini.get("start" , agentname); agent agent1 = _agents.get(agent); if (agent == null){ system.out.print("error"); homecoming null; } else { homecoming agent1; } homecoming null; }

java

No comments:

Post a Comment