Я пытаюсь запустить программу Java, подав args
в Eclipse. Это часть кода, который вызывает ошибку:Java «FileNotFoundException» при подаче аргументов Eclipse
//Store the occupancy matrix in a bitmap image
new BMP().saveBMP(args[2],occupancy);
и это ошибка, я получаю:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\Gian\AIprojects\Homework1\Map.bmp (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at Main.main(Main.java:31)
Я кормил аргументы через Run -> Run Configurations..
, а затем на вкладке Arguments
. Это скриншот вкладки (второй аргумент является тот, который поднимает ошибку):
И это то, что делает класс BMP:
public void saveBMP(String filename, int [][] rgbValues){
try {
FileOutputStream fos = new FileOutputStream(new File(filename));
bytes = new byte[54 + 3*rgbValues.length*rgbValues[0].length + getPadding(rgbValues[0].length)*rgbValues.length];
saveFileHeader();
saveInfoHeader(rgbValues.length, rgbValues[0].length);
saveRgbQuad();
saveBitmapData(rgbValues);
fos.write(bytes);
fos.close();
} catch (FileNotFoundException e)
}
Я должен также упомянуть что на вкладке «Аргументы» я попытался не указывать путь, а просто имя файла «Map.bmp», но он поднимает ту же ошибку. Кто-нибудь знает, где проблема? Благодаря
EDIT: Это Main (нет арга [0], они начинают с арг 1):
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException, Exception{
//Input file must be specified in args[1]
BufferedReader reader = new BufferedReader(new FileReader(new File(args[1])));
int v = Integer.parseInt(args[3]);
// int v = 0;
int m = (int) pow(2,v);
System.out.println("M: " + m);
//Read from the file and set the grid dimensions
StringTokenizer tokens = new StringTokenizer(reader.readLine());
int maxX = Integer.parseInt(tokens.nextToken())*m;
int maxY = Integer.parseInt(tokens.nextToken())*m;
System.out.println("maxX: " + maxX + " maxY: " + maxY);
//Store the matrix of integers that will be written in the .bmp file
//and initialize it with white cells
int[][] occupancy = new int[maxX][maxY];
for(int i=0; i<maxX; i++)
for(int j=0; j<maxY; j++)
occupancy[i][j] = 16777215;
//Read from the file the start and the goal position
//and store them in the occupancy matrix
tokens = new StringTokenizer(reader.readLine());
XYLocation robot = new XYLocation(Integer.parseInt(tokens.nextToken())*m,Integer.parseInt(tokens.nextToken())*m);
System.out.println("Robot");
System.out.println("X: " + robot.getXCoOrdinate() + " Y: " + robot.getYCoOrdinate());
occupancy[robot.getYCoOrdinate()][robot.getXCoOrdinate()] = 255;
tokens = new StringTokenizer(reader.readLine());
XYLocation finish = new XYLocation(Integer.parseInt(tokens.nextToken())*m,Integer.parseInt(tokens.nextToken())*m);
System.out.println("Goal");
System.out.println("X: " + finish.getXCoOrdinate() + " Y: " + finish.getYCoOrdinate());
occupancy[finish.getYCoOrdinate()][finish.getXCoOrdinate()] = 65280;
//Build the environment
Environment init = new Environment(robot);
Environment.setFinish(finish);
int numWalls = Integer.parseInt(reader.readLine());
for(int i=0; i < numWalls; i++) {
tokens = new StringTokenizer(reader.readLine());
XYLocation temp = new XYLocation(Integer.parseInt(tokens.nextToken())*m,Integer.parseInt(tokens.nextToken())*m);
for(int x=0; x < m; x++)
for(int y=0; y < m; y++) {
int newX = temp.getXCoOrdinate()+x;
int newY = temp.getYCoOrdinate()+y;
Environment.addWall(new XYLocation(newX,newY));
occupancy[newY][newX] = 0x000000;
}
}
//Store the occupancy matrix in a bitmap image
new BMP().saveBMP(args[2],occupancy);
// new BMP().saveBMP("Map.bmp",occupancy);
//Use AIMA framework to solve the problem
Problem problem = new Problem(init, RobotFunctionFactory.getActionsFunction(),
RobotFunctionFactory.getResultFunction(), new RobotGoalTest());
RobotWithAStarSearch(problem, robot, occupancy);
RobotWithDepthFirstSearch(problem, robot, occupancy);
}
Я пробовал оба «/» и «\\», но я продолжаю получать ошибку. –
Я не понимаю, что BMP должен создать новый файл FileOutputStream. Почему он должен давать исключение FileNotFoundException, если оно предназначено для его создания? –
Вы вызываете BMP.saveBMP с параметром args [2], который равен 0 из вашего списка args. Может быть, вы можете использовать args [1] – Massimo