The project doesn’t work in other computers
已回答
The resources of the project can’t be accessed by the system when I use different computers.I want to know how to change the absolute path .I have try some recommended methods but the login frame continuously shows that the user doesn’t exist.
请先登录再写评论。
Hello,
Could you please provide more details about the problem?
Feel free to use screenshots or code snippets, and describe the expected vs. actual result.
Hi,
I have a uni project about renting a car and it needs to be working on different devices but my program works only in my working computer.It is a gui app and the program needs to recognise the provided csv files to work.When you run the main,the result is a login frame and you use one of the required users for the initialisation. I have tried finding the solution from different sources like not using absolute path but the problem is still the same .The structure of the project is CAR_RENT_project_despoina/
.ideaout
resources/
customers.csv
users.csv
vehicles_with_plates.csv
src/
api/
Car.java
Customer.java
DataManager.java
Employee.java
Rental.java
gui/
Main.java
The code is in data management and it is:
package api;import java.util.*;import java.time.LocalDate;import java.io.*;import java.nio.charset.StandardCharsets;
public class DataManager {
public HashMap<String, Employee> employees = new HashMap<>();
public HashMap<String, Customer> customers = new HashMap<>();
public HashMap<Integer, Car> cars = new HashMap<>();
public HashMap<Integer, Rental> rentals = new HashMap<>();
private int nextRentalId = 1;
private final String vehiclesCSV = “C:/USERS/despo/Desktop/CAR RENT project_despoina/resources/vehicles_with_plates.csv”;private final String usersCSV = "C:/USERS…/resources/users.csv";
private final String customersCSV = "C:/USERS…/resources/customers.csv";
public DataManager(){
loadEmployees();
loadCars();
loadCustomers();
}
Hello Bariemaib
As you mention, the absolute paths (like
C:/Users/despo/...), which are hardcoded, address a specific path to your own computer's file system. When you move the project to another device, the system looks for that exact folder structure, which appears not to match the user.So, in a Java project, relative paths are resolved starting from the Project Root (the
CAR_RENT_project_despoinafolder). You need to change your hardcoded strings to point to theresourcesfolder relative to the project root. Here is a proposal on how to update yourDataManager.javato make it portable:It will work for anyone, as long as they have the
resourcesfolder inside the project folder. So, verify on the other computer that the user has enough privileges to access the directory.If the login frame still says "user doesn't exist" after this change, check these two things:
Run->Edit Configurations.... Look at your main application configuration and ensure the Working directory is set to your project root (e.g.,.../CAR_RENT_project_despoina).resourcesvsResources).Happy holidays!