I'm writing a code where I need HashMap, but it throws an error:
The type java.io.Serializable cannot be resolved. It is indirectly referenced from required .class files
I tried to import java.io.Serializable but it says cannot be resolved. I tried to find solutions but they are all related to updating pom files etc, in my case I'm just creating a simple java class.
JDK Version: jdk-11.0.9
Here is my code:
import java.util.HashMap;
import java.util.Scanner;
public class BankApp {
static String getMainMenu() {
String menuChoice;
Scanner in = new Scanner(System.in);
System.out.println("-----------*************-----------");
System.out.println("Choose an option:");
System.out.println("1. Add New Customer");
System.out.println("2. Search Existing Customer");
System.out.println("-----------*************-----------");
System.out.print("Enter your choice: ");
menuChoice = in.nextLine();
in.close();
return menuChoice;
}
static Customer register() {
String id;
String name;
String gender;
String location;
int accountType;
int accountNo;
Scanner in = new Scanner(System.in);
System.out.println("-----------*************-----------");
System.out.print("Enter ID No.: \t");
id = in.nextLine();
System.out.print("Enter Name: \t");
name = in.nextLine();
System.out.print("Enter Gender(M/F): \t");
gender = in.nextLine();
System.out.print("Enter Location: \t");
location = in.nextLine();
System.out.print("Enter A/C Type(0 = Savings, 1 = Current): \t");
accountType = in.nextInt();
System.out.print("Enter A/C No: \t");
accountNo = in.nextInt();
System.out.println("-----------*************-----------");
in.close();
return new Customer(id, name, gender, location, accountType, accountNo);
}
public static void main(String ...args) {
HashMap<String, Customer> customerMap = new HashMap<String, Customer>();
String mainMenuChoice = BankApp.getMainMenu();
switch(mainMenuChoice) {
case "1":
Customer newCustomer = BankApp.register();
System.out.println(newCustomer.name);
customerMap.put(newCustomer.id, newCustomer);
break;
default:
break;
}
}
}
class Customer {
String id;
String name;
String gender;
String location;
int accountType;
int accountNo;
Customer(String id, String name, String gender, String location, int accountType, int accountNo) {
this.id = id;
this.name = name;
this.gender = gender;
this.location = location;
this.accountType = accountType;
this.accountNo = accountNo;
}
public void print() {
System.out.println("-----------*************-----------");
System.out.print("ID: \t" + this.id);
System.out.print("Name: \t" + this.name);
System.out.println("Gender: \t" + this.gender);
System.out.println("Location: \t" + this.location);
System.out.format("A/C Type: \t%d", this.accountType);
System.out.format("A/C No.: \t%d", this.accountNo);
System.out.println("-----------*************-----------");
}
}
