1
Today I tried to make a login system (again), only this time I used a array one-dimensional to guard my values. When I ran my program, Eclipse had an error (null pointer to be more specific), my theory is that assign a value to array caused the error.
Follow my code below:
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);
}
}
}
Simply the code assigns the user name to log.valores[1]
and the password to log.valores[2]
and log.valores[3]
serves only to confirm the password.
Just a little observation, vectors start from Indice 0, it is good to get used to and adapt to it.
– user28595