Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to understand Java Code which gives an error on compiling that index out of bound. I am trying to figure out why it is giving this error but failed. Can anyone help me that why this code is giving index out of bound error?

C#
try {
			ORB orb = ORB.init(args, null);
			POA rootpoa = POAHelper.narrow(orb
					.resolve_initial_references("RootPOA"));
			rootpoa.the_POAManager().activate();

			ProfilerServant profilerServant = new ProfilerServant(args[4],
					args[5].equals("true"));
			org.omg.CORBA.Object ref = rootpoa
					.servant_to_reference(profilerServant);
			Profiler pref = ProfilerHelper.narrow(ref);

			org.omg.CORBA.Object objRef = orb
					.resolve_initial_references("NameService");
			NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

			String name = "Profiler";
			NameComponent path[] = ncRef.to_name(name);
			ncRef.rebind(path, pref);

			orb.run();
		}

		catch (Exception e) {
			System.err.println("ERROR: " + e.getMessage());
			e.printStackTrace(System.out);
		}
	}


Here is the ProfilerServant Class
with the constructor

<pre lang="c#">public class ProfilerServant extends ProfilerPOA {

	boolean cacheEnabled;

	ServerParser parser;
	HashMap<String, Integer> songCache;
	HashMap<String, User> userCache;

	ProfilerServant(String fileName, boolean cacheEnabled) {
		this.cacheEnabled = cacheEnabled;
		parser = new ServerParser(fileName);
		songCache = new HashMap<String, Integer>();
		userCache = new HashMap<String, User>();
		init();
	}
Posted

Simple index out of bound means that in a list or an array, you try to access an element that doesn't exist.

Example: in an array of 5 integers numbered from 0 to 4, you try to read integer number 5, which does not exist.

Telling what is the error message is nice, but telling where is the error message is better, it helps to narrow the research.

Without seeing the array involved, it will be complicated to help you further.
If you get the error message at compile time, you array is probably a constant.
If you get the error message at runtime, use the debugger and check the variables where error occurs.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 26-Sep-15 4:37am    
5ed.
CPallini 26-Sep-15 8:17am    
5.
Java
ProfilerServant profilerServant = new ProfilerServant(args[4], args[5].equals("true"));

Are you certain that args has 6 elements?
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 26-Sep-15 4:38am    
5ed; If only he gets the point. :-)
CPallini 26-Sep-15 8:17am    
5. Good guess.
Richard MacCutchan 26-Sep-15 8:43am    
Guess? Logical analysis my friend.
CPallini 26-Sep-15 9:20am    
Of course! :thumbsup:
Patrice T 26-Sep-15 8:52am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900