Today I tried to make a login system (again), but this time I used a one-dimensional array to save my values. When I ran my program, Eclipse accused an error (null pointer to be more specific), my theory is that assigning a value to array caused the error.
Below is my code:
package com.Login;
import java.util.Scanner;
import java.util.Random;
public class Login {
Random r = new Random();
String[] valores;
boolean isSessionValid;
int sessID = r.nextInt();
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Login log = new Login();
System.out.println("Digite o nome do usuário:");
log.valores[1] = in.nextLine();
System.out.println("Digite sua senha:");
log.valores[2] = in.nextLine();
System.out.println("Digite novamente a senha:");
log.valores[3] = in.nextLine();
if(log.valores[3].equals(log.valores[1])){
System.out.println("Você está logado!");
log.isSessionValid = true;
System.out.println("Sua Sessão é:"+log.sessID);
}
}
}
The code assigns the user name to log.valores[1]
and the password to log.valores[2]
and log.valores[3]
is only used to confirm the password.