2
I’m trying to check if the product registration fields are empty, probably the error is in the declaration of if
, that was to is returning the error message:
"Unfilled fields, try again"
With the application running, if I fill in all fields of the product registration it works perfectly, and reaches the table in the bank, but if I press the sign up button with the empty fields it was for him to show me the error message, but instead, the app hangs and restarts.
Process: com.example.rodrigoconceicao.controleestoque2_1, PID: 2818
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:539)
at com.example.rodrigoconceicao.controleestoque2_1.CadastroProduto$1.onClick (CadastroProduto.java:54)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
2018-11-08 16:13:46.384 492-1756/system_process E/EGL_emulation: tid 1756: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
2018-11-08 16:13:56.703 492-509/system_process E/memtrack: Couldn't load memtrack module
2018-11-08 16:16:00.004 492-509/system_process E/memtrack: Couldn't load memtrack module
2018-11-08 16:18:00.006 492-509/system_process E/memtrack: Couldn't load memtrack module
2018-11-08 16:18:46.615 492-1165/system_process E/ActivityManager: Found activity ActivityRecord{4229246 u0 com.example.rodrigoconceicao.controleestoque2_1/.TelaLogin t-1 f} in proc activity list using null instead of expected ProcessRecord{60cfefe
2818:com.example.rodrigoconceicao.controleestoque2_1/u0a68}
2018-11-08 16:18:46.643 492-563/system_process E/InputDispatcher: channel '512a963 com.example.rodrigoconceicao.controleestoque2_1/com.example.rodrigoconceicao.controleestoque2_1.CadastroProduto (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-11-08 16:18:46.643 492-563/system_process E/InputDispatcher: channel 'fad8f39 com.example.rodrigoconceicao.controleestoque2_1/com.example.rodrigoconceicao.controleestoque2_1.TelaPrincipal (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-11-08 16:18:46.643 492-563/system_process E/InputDispatcher: channel 'fb3b8a9 com.example.rodrigoconceicao.controleestoque2_1/com.example.rodrigoconceicao.controleestoque2_1.Produtos (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-11-08 16:18:46.643 492-563/system_process E/InputDispatcher: channel '324fdd0 com.example.rodrigoconceicao.controleestoque2_1/com.example.rodrigoconceicao.controleestoque2_1.TelaLogin (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-11-08 16:18:46.833 1168-1315/com.android.launcher3 E/EGL_emulation: tid 1315: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
2018-11-08 16:19:00.004 492-509/system_process E/memtrack: Couldn't load memtrack module
This is the error message!
public class CadastroProduto extends AppCompatActivity {
Spinner spnFornecedor, spnUMedida;
EditText edtDescricao, edtCategoria, edtVCusto, edtVVenda, edtEAtual, edtEMinimo;
Button btnNFornecedor, btnCadastrar02;
DBHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cadastro_produto);
db = new DBHelper(this);
spnFornecedor = (Spinner) findViewById(R.id.spnFornecedor);
spnUMedida = (Spinner) findViewById(R.id.spnUMedida);
edtDescricao = (EditText) findViewById(R.id.edtDescricao);
edtCategoria = (EditText) findViewById(R.id.edtCategoria);
edtVCusto = (EditText) findViewById(R.id.edtVCusto);
edtVVenda = (EditText) findViewById(R.id.edtVVenda);
edtEAtual = (EditText) findViewById(R.id.edtEAtual);
edtEMinimo = (EditText) findViewById(R.id.edtEMinimo);
btnNFornecedor = (Button) findViewById(R.id.btnNFornecedor);
btnCadastrar02 = (Button) findViewById(R.id.btnCadastrar02);
ArrayAdapter adapterUM = ArrayAdapter.createFromResource (this,R.array.unidade_medida, android.R.layout.simple_spinner_item);
spnUMedida.setAdapter(adapterUM);
btnCadastrar02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Produto produto = new Produto();
//String fornecedor = spnFornecedor.getSelectedItem().toString();
produto.setUnidadeMedida(spnUMedida.getSelectedItem().toString());
produto.setDescricao(edtDescricao.getText().toString());
produto.setCategoria(edtCategoria.getText().toString());
produto.setValorCusto (Double.parseDouble(edtVCusto.getText().toString()));
produto.setValorVenda(Double.parseDouble(edtVVenda.getText().toString()));
produto.setEstoqueAtual(Integer.parseInt(edtEAtual.getText().toString()));
produto.setEstoqueMinimo(Integer.parseInt(edtEMinimo.getText().toString()));
//String unidadeMedida = spnUMedida.getSelectedItem().toString();
/*String descricao = edtDescricao.getText().toString();
String categoria = edtCategoria.getText().toString();
String valorCusto = edtVCusto.getText().toString();
String valorVenda = edtVVenda.getText().toString();
String estoqueAtual = edtEAtual.getText().toString();
String estoqueMinimo = edtEMinimo.getText().toString();*/
if (edtDescricao.getText().toString().equals(null) ||
edtCategoria.getText().toString().equals(null) ||
edtVCusto.getText().toString().equals(null) ||
edtVVenda.getText().toString().equals(null) ||
edtEAtual.getText().toString().equals(null) ||
edtEMinimo.getText().toString().equals(null)) {
Toast.makeText(CadastroProduto.this, "Campos não preenchidos, tente novamente", Toast.LENGTH_SHORT).show();
}
else {
long res = db.CriarProduto(produto);
if (res>0){
Toast.makeText(CadastroProduto.this, "Produto cadastrado", Toast.LENGTH_SHORT).show();
Intent i = new Intent (CadastroProduto.this, Produtos.class);
startActivity(i);
}else {
Toast.makeText(CadastroProduto.this, "Cadastro invalido, tente novamente", Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
This is where the message indicates the error, but right on the line that says
"SetValorCusto (Double.parseDouble(edtVCusto.gettext(). toString()); (line 54)".
There are some parts of code commented because I am testing various forms.