Hi, I'm trying to input a random number of Strings by passing them in as args[]. When I try to use a for loop to determine when there is no more arguments left it gives me an "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10" error. I've tried looking for a null spot at the end but that doesn't seem to work. I've resorted to passing in two null Strings to determine where the end is. My question is if there is an easier way to do this, such that I don't need to pass anything special in with my args.
//Starts the main Method
public static void main(String[] args) {
Main main = new Main();
String ip = args[0];
String username = args[1];
String password = args[2];
String pathname = "C:/Automation/Scripts/test_files/smoke/";
String filename = pathname + "fw4.pdf";
ArrayList keys = new ArrayList();
ArrayList values = new ArrayList();
main.getattrs(args[0],args[1],args[2],args[3]);
main.init();
main.connect(ip,username,password);
//Sets the keys to be set
for(int count = 4;!args[count].equals("null");count = count+2){
int index = 0;
keys.add(args[count]);
index++;
}
//Sets the key values to be set
for(int count = 5;!args[count].equals("null");count = count+2){
int index = 0;
values.add(args[count]);
index++;
}
//Creates a job to change the values of
byte[] JOBID = main.makeJob(ip,"hold",filename);
//Checks to make sure the keys and values arrays have the same number
//of elements
int keylength = keys.size();
int valuelength = values.size();
if(keylength != valuelength){
System.out.println("Error in inputed keys and values!");
}
//Changes the keys and values of a job
System.out.println("Changing "+keylength+" attributes!");
for(int index = 0;index < keylength;index++){
main.setJobAttributes(JOBID,keys.get(index).toString(),values.get(index).toString());
}
main.disconnect();
}
//End main method
Thanks