Apparently I managed to solve this problem myself.In LoginActivity I had the main 'Xml'(activity_login.xml), and a 'Diolog' (register.xml), the problem was that I had associated the 'CheckBox' in the prncipal and not in the register that was where it was created.
To solve this just take the...termosUso = (CheckBox) findViewById(R.id.termosUso2);
from onCreate in the login and put it in its proper place, i.e. inside ClickSignUp(), and add the 'dialogView.', in the code line getting exactly like this...termosUso = (CheckBox) dialogView.findViewById(R.id.termosUso2);
and the whole code like that.package app.conect.medicconect1;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
public class LoginActivity extends AppCompatActivity {
protected EditText emaillog, password;//Parte de Login
protected Button login, cadastreSe, desn;//Tela de Login
protected TextInputLayout txtInLayoutUsername, txtInLayoutPassword, txtInLayoutRegPassword;//2 telas (LAYOUT)
protected CheckBox rememberMe;//Tela de Login
private String HOST = "http://192.168.0.4/LoginApp/";//HOST da pasta do mysql para ter acesso aos arquivos
protected EditText nomeCad, apelidoCad, emailCad, passwordCad,
passwordConfCad;//Parte de cadastro
protected Button cadastroCad, btnUso;//Tela de cadastro
protected CheckBox termosUso;//Tela de cadastro
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
emaillog = findViewById(R.id.emaillog2);
password = findViewById(R.id.password2);
login = findViewById(R.id.login2);
cadastreSe = findViewById(R.id.cadastreSe2);
desn = findViewById(R.id.desenvolvedor2);
txtInLayoutUsername = findViewById(R.id.txtInLayoutUsername);
txtInLayoutPassword = findViewById(R.id.txtInLayoutPassword);
rememberMe = findViewById(R.id.rememberMe);
ClickLogin();
cadastreSe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClickSignUp();
}
});
desn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
Intent abreHome = new Intent(LoginActivity.this, homeActivity.class);
startActivity(abreHome);
}
});
}
public void ClickLogin () {...}
public void ClickUso () {...}
public void ClickSignUp() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.register, null);
dialog.setView(dialogView);
nomeCad = dialogView.findViewById(R.id.nomeCad2);
apelidoCad = dialogView.findViewById(R.id.apelidoCad2);
passwordCad = dialogView.findViewById(R.id.passwordCad2);
passwordConfCad = dialogView.findViewById(R.id.passwordConfCad2);
emailCad = dialogView.findViewById(R.id.emailCad2);
cadastroCad = dialogView.findViewById(R.id.cadastroCad2);
btnUso = dialogView.findViewById(R.id.btnUso);
txtInLayoutRegPassword = dialogView.findViewById(R.id.txtInLayoutRegPassword);
termosUso = (CheckBox) dialogView.findViewById(R.id.termosUso2);
btnUso.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
ClickUso();
}
});
cadastroCad.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
String nome = nomeCad.getText().toString();
String apelido = apelidoCad.getText().toString();
String email = emailCad.getText().toString();
String senha = passwordCad.getText().toString();
String senhaConf = passwordConfCad.getText().toString();
String URL = HOST + "cadastrar.php";
if (nomeCad.getText().toString().trim().isEmpty()) {
nomeCad.setError("Por favor, preencha este campo");
} if (passwordCad.getText().toString().trim().isEmpty()) {
passwordCad.setError("Por favor, preencha este campo");
} if (apelidoCad.getText().toString().trim().isEmpty()) {
apelidoCad.setError("Por favor, preencha este campo");
} if (emailCad.getText().toString().trim().isEmpty()) {
emailCad.setError("Por favor, preencha este campo");
} if (passwordConfCad.getText().toString().trim().isEmpty()) {
passwordConfCad.setError("Por favor, preencha este campo");
}
if (senhaConf.equals(senha)){
if (nome.trim().isEmpty() || apelido.trim().isEmpty() || email.trim().isEmpty() || senha.trim().isEmpty() || senhaConf.trim().isEmpty()) {
Toast.makeText(LoginActivity.this, "Por Favor verifique se os campos estão preenchidos corretamente.", Toast.LENGTH_LONG).show();
}else {
if (termosUso.isChecked()) {
Ion.with(LoginActivity.this)
.load(URL)
.setBodyParameter("nome_app", nome)
.setBodyParameter("apelido_app", apelido)
.setBodyParameter("email_app", email)
.setBodyParameter("senha_app", senha)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
try {
// Toast.makeText(cadastroActivity.this, "Nome: " + result.get("NOME").getAsString(), Toast.LENGTH_LONG).show();
String RETORNO = result.get("CADASTRO").getAsString();
if (RETORNO.equals("EMAIL_ERRO")) {
Toast.makeText(LoginActivity.this, "Ops! Este email já está cadastrado", Toast.LENGTH_LONG).show();
} else if (RETORNO.equals("SUCESSO")) {
// Toast.makeText(cadastroActivity.this, "Cadastrado com sucesso", Toast.LENGTH_LONG).show();
Intent abreHome = new Intent(LoginActivity.this, homeActivity.class);
startActivity(abreHome);
} else {
Toast.makeText(LoginActivity.this, "Ops! Ocorreu um erro", Toast.LENGTH_LONG).show();
}
} catch (Exception erro) {
Toast.makeText(LoginActivity.this, "ops! Ocorreu um erro, " + erro, Toast.LENGTH_LONG).show();
}
}
});
}else{
Toast.makeText(LoginActivity.this, "Para continuar é preciso concordar com os termos de uso!", Toast.LENGTH_LONG).show();
}
} //fecha else dos campos preenchidos
}else {
Toast.makeText(LoginActivity.this, "Senhas Diferentes!", Toast.LENGTH_LONG).show();
passwordConfCad.setError("Por favor, preencha este campo");
}
}
});
dialog.show();
}
}
In short I called an item in a place where it did not exist.