在 Java 中的方法之前崩溃

Crash before a method in Java

我在大学 activity 工作,我试图做一个带有选项的菜单,但是当我输入选项“A”来介绍用户并通过验证用户并登录时系统,程序不动,不问用户。在 system.out.blablaba 选项 A 或 B 之前。 我只想知道键盘输入是否与用户和密码数组中的某些元素相关

package com.app;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
//cmd_in
static Scanner entradaConsola = new Scanner(System.in);

public static void main(String[] args) throws FileNotFoundException {
    int cantMax = 10;
    String[] nombresVendedores = new String[cantMax];
    String[] passVendedores = new String[cantMax];
    String[] codPeliculas = new String[cantMax];
    String[] nombrePeliculas = new String[cantMax];
    String[] salaPeliculas = new String[cantMax];
    int[] dispAsientos = new int[cantMax];
    int[] precioEntrada = new int[cantMax];
    String opcion = "1";
    int cantVendedores = leerArchivos("vendedores.txt", opcion,nombresVendedores,passVendedores,codPeliculas,nombrePeliculas,
            salaPeliculas,dispAsientos,precioEntrada);
    opcion = "2";
    int cantPeliculas = leerArchivos("peliculas.txt", opcion,nombresVendedores,passVendedores,codPeliculas,nombrePeliculas,
            salaPeliculas,dispAsientos,precioEntrada);

    while (true){
        System.out.println("=== WELCOME TO CINE HOYTS ===");
        System.out.println("Choose one option: ");
        System.out.println("A) Login");
        System.out.println("B) Exit");


        String eleccion = entradaConsola.nextLine();

        if (eleccion.equalsIgnoreCase("a")){
            String user = entradaConsola.nextLine();
            String pass = entradaConsola.nextLine();
            if (verificarUsuario(nombresVendedores,passVendedores,cantVendedores,user,pass)){
                System.out.println("Sucesfull Login");
                System.out.println(cantPeliculas);
            }else
                System.out.println("User/Password incorrect.");

        }else if (eleccion.equalsIgnoreCase("b")){
            System.out.println("Good Bye. EXITING!");
            break;
        }else
            System.out.println("Wrong options");
    }
}

// read file
public static int leerArchivos(String nombreArchivo, String opcion, String[] nombresVendedores, String[] passVendedores,
                                String[] codPeliculas, String[] nombrePeliculas, String[] salaPeliculas, int[] dispAsientos,
                                int[] precioEntradas) throws FileNotFoundException {
    File archivo = new File(nombreArchivo);
    Scanner lector = new Scanner(archivo);
    int cant = 0;

    switch (opcion){
        case "1" -> {
            while (lector.hasNextLine()){
                String linea = lector.nextLine();
                String[] partes = linea.split(",");
                nombresVendedores[cant] = partes[0];
                passVendedores[cant] = partes[1];
                cant++;

            }

        }
        case "2" -> {
            while (lector.hasNextLine()){
                String linea = lector.nextLine();
                String[] partes = linea.split(",");
                codPeliculas[cant] = partes[0];
                nombrePeliculas[cant] = partes[1];
                salaPeliculas[cant] = partes[2];
                dispAsientos[cant] = Integer.parseInt(partes[3]);
                precioEntradas[cant] = Integer.parseInt(partes[4]);
                cant++;

            }
        }
    }
return cant;
}
// Verify if user exists
public static boolean verificarUsuario(String[] nombresVendedores, String[] passVendedores, int cantVendedores,String user,String pass){
    for (int i = 0; i < cantVendedores; i++){
        if (nombresVendedores[i].equalsIgnoreCase(user)){
            if (passVendedores[i].equalsIgnoreCase(pass)){
                return true;
            }

        }
    }
    return false;
}

}

我认为你的程序已经在工作了...

在获取用户并通过之前只需打印一条文本。那就更清楚了...

System.out.println("Enter username:");
String user = entradaConsola.nextLine();
System.out.println("Enter password:");
String pass = entradaConsola.nextLine();