[android-developers] Blank Edit Text Problem
I'm making kind of a calculator and everything is working fine. Except when I leave one of the 4 EditText fields blank, the application cracks (stops unexpectly). How can I work this out? It would be good to, when this happens (EditText blank) just put a empty message at the destination. Part of the code: public void onClick(View arg0) { double result = new Double(input1.getText().toString()) * new Double(input3.getText().toString()); conta.setText(Double.toString(result)); double result2 = new Double(input1.getText().toString()) * new Double(input3.getText().toString()) / new Double(input4.getText().toString()); porpessoa.setText(Double.toString(result2)); double result3 = new Double(input1.getText().toString()) * new Double(input2.getText().toString()); totallitros.setText(Double.toString(result3)); double result4 = new Double(input1.getText().toString()) * new Double(input2.getText().toString())/ new Double(input4.getText().toString()); litrosporpessoa.setText(Double.toString(result4)); } -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Blank Edit Text Problem
07.04.2011 15:57, Gabriel пишет: I'm making kind of a calculator and everything is working fine. Except when I leave one of the 4 EditText fields blank, the application cracks (stops unexpectly). How can I work this out? In general, when something like this happens, you use the debugger to find out what's really happening. Some ideas: When an EditText is empty, its getText returns null. When you call toString() on a null object, you get a NullPointerException. It would be good to, when this happens (EditText blank) just put a empty message at the destination. Take a look at this: http://developer.android.com/reference/android/widget/TextView.html#setError(java.lang.CharSequence) -- Kostya Vasilyev -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en