1
Good Morning, I have this mistake :
No suitable parent found from the given view. Please provide a valid view.
I’m entering the registration view and this returning me this message, tried to fix it could not i tbm tried to put a view but tbm failed
this is the registration view code:
package com.betelhosting.dev.carteiradecliente;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import com.betelhosting.dev.carteiradecliente.database.DadosOpenHelper;
import com.betelhosting.dev.carteiradecliente.dominio.entidades.Cliente;
import com.betelhosting.dev.carteiradecliente.dominio.repositorio.ClienteRepositorio;
public class ActCadCliente extends AppCompatActivity {
private EditText edtNome;
private EditText edtEndereco;
private EditText edtEmail;
private EditText edtTelefone;
private ConstraintLayout layoutContentActCadCliente;
private ClienteRepositorio clienteRepositorio;
private SQLiteDatabase conexao;
private DadosOpenHelper dadosOpenHelper;
private Cliente cliente;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_cad_cliente);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
edtNome = (EditText) findViewById(R.id.edtNome);
edtEndereco = (EditText) findViewById(R.id.edtEndereco);
edtEmail = (EditText) findViewById(R.id.edtEmail);
edtTelefone = (EditText) findViewById(R.id.edtTelefone);
layoutContentActCadCliente = (ConstraintLayout) findViewById(R.id.layoutContentActCadCliente);
criarConexao();
}
private void criarConexao() {
try {
dadosOpenHelper = new DadosOpenHelper(this);
conexao = dadosOpenHelper.getWritableDatabase();
Snackbar.make(layoutContentActCadCliente, "Conexão criada com Sucesso", Snackbar.LENGTH_LONG)
.setAction("OK", null).show();
} catch (Exception ex) {
android.support.v7.app.AlertDialog.Builder dlg = new android.support.v7.app.AlertDialog.Builder(this);
dlg.setTitle(R.string.title_erro);
dlg.setMessage(ex.getMessage());
dlg.setNeutralButton(R.string.action_ok, null);
dlg.show();
}
}
private void confirmar() {
cliente = new Cliente();
if (validaCampos() == false) {
try {
clienteRepositorio.inserir(cliente);
finish();
} catch (Exception ex) {
android.support.v7.app.AlertDialog.Builder dlg = new android.support.v7.app.AlertDialog.Builder(this);
dlg.setTitle(R.string.title_erro);
dlg.setMessage(ex.getMessage());
dlg.setNeutralButton(R.string.action_ok, null);
dlg.show();
}
}
}
@SuppressLint("ResourceType")
private boolean validaCampos() {
boolean res = false;
String nome = edtNome.getText().toString();
String endereco = edtEndereco.getText().toString();
String email = edtEmail.getText().toString();
String telefone = edtTelefone.getText().toString();
if (res = isCampoVazio(nome)) {
edtNome.requestFocus();
} else
if (res = isCampoVazio(endereco)) {
edtEndereco.requestFocus();
} else
if (res = !isEmailValido(email)) {
edtEmail.requestFocus();
} else
if (res = isCampoVazio(telefone)) {
edtTelefone.requestFocus();
}
if (res) {
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle("Aviso");
dlg.setMessage(R.string.message_campos_invalidos_brancos);
dlg.setNeutralButton(R.id.action_ok, null);
dlg.show();
}
return res;
}
private boolean isCampoVazio(String valor) {
boolean resultado = (TextUtils.isEmpty(valor) || valor.trim().isEmpty());
return resultado;
}
private boolean isEmailValido(String email) {
boolean resultado = (!isCampoVazio(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches());
return resultado;
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_act_cad_cliente, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_ok:
confirmar();
//Toast.makeText(this, "Botão OK Selecionado", Toast.LENGTH_SHORT).show();
break;
case R.id.action_cancelar:
//Toast.makeText(this, "Botão OK Selecionado", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
this is from the beginning:
package com.betelhosting.dev.carteiradecliente;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.betelhosting.dev.carteiradecliente.database.DadosOpenHelper;
import java.sql.SQLException;
public class ActMain extends AppCompatActivity {
private RecyclerView lstDados;
private FloatingActionButton fab;
private ConstraintLayout layoutContentMain;
private SQLiteDatabase conexao;
private DadosOpenHelper dadosOpenHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = (FloatingActionButton)findViewById(R.id.fab);
lstDados = (RecyclerView)findViewById(R.id.lstDados);
layoutContentMain = (ConstraintLayout)findViewById(R.id.layoutContentMain);
criarConexao();
}
private void criarConexao(){
try{
dadosOpenHelper = new DadosOpenHelper(this);
conexao = dadosOpenHelper.getWritableDatabase();
Snackbar.make( layoutContentMain, R.string.message_conexao_criada_com_sucesso, Snackbar.LENGTH_LONG)
.setAction(R.string.action_ok, null).show();
}catch(Exception ex){
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.setTitle(R.string.title_erro);
dlg.setMessage(ex.getMessage());
dlg.setNeutralButton(R.string.action_ok, null);
dlg.show();
}
}
public void cadastrar(View view){
Intent it = new Intent(ActMain.this, ActCadCliente.class);
startActivity(it);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_act_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Guy made a mistake in Brazil
– FelipeBr193