In: Computer Science
when i run the program on eclipse it gives me this error:
Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for
length 0
at SIM.main(SIM.java:12)
how do I fix that ? (please fix it )
import java.util.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.Math;
public class SIM{
public static void main(String[] args) throws
FileNotFoundException
{
int cacheSize = Integer.parseInt( args[1] );
int assoc = Integer.parseInt( args[2] );
int replacement = Integer.parseInt( args[3] );
int WB = Integer.parseInt( args[4] );
File traces = new File(args[5]);
Scanner s = new Scanner(traces);
int numSets = cacheSize / (64 * assoc);
int[][] cache = new int[600][64];
int hits = 0;
int misses = 0;
int reads = 0;
int writes = 0;
int addressCount = 0;
int numSetBits = (int)(Math.log(numSets)/Math.log(2.0));
.
.
.
.
..
If you have any doubts, please give me comment...
import java.util.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.Math;
public class SIM {
public static void main(String[] args) throws FileNotFoundException {
if(args.length<6){
System.out.println("Usage: java SIM <optional-param> <cacheSize> <assoc> <replacement> <WB> <traces>");
System.exit(0);
}
int cacheSize = Integer.parseInt(args[1]);
int assoc = Integer.parseInt(args[2]);
int replacement = Integer.parseInt(args[3]);
int WB = Integer.parseInt(args[4]);
File traces = new File(args[5]);
Scanner s = new Scanner(traces);
int numSets = cacheSize / (64 * assoc);
int[][] cache = new int[600][64];
int hits = 0;
int misses = 0;
int reads = 0;
int writes = 0;
int addressCount = 0;
int numSetBits = (int) (Math.log(numSets) / Math.log(2.0));
// your additional statements
}
}