tags:

views:

56

answers:

1

Double temp_val = 0.0;

temp_val = Double.parseDouble(et1.getText().toString()); if (temp_val < 14) {

                            final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
                            alertDialog.setTitle("Reset...");
                            alertDialog.setMessage("WB should be greater than or equal to 14");
                            alertDialog.setButton2("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) 
                                {
                                      // here you can add functions
                                    dialog.dismiss();
                                }
                            });
                            alertDialog.setIcon(R.drawable.icon);
                            alertDialog.show();
                            et1.setText("");    
                            tv1.setText("WB");
                            return;
                        }
                        double p = 1.8;
                        double fvalue = p;
                        temp_val = temp_val * fvalue;
                        temp_val = (temp_val + 32);

                        String temp_val1=Double.toString(temp_val);
                        wbval = Integer.parseInt(temp_val1);

                    }   

and i Got the following Exception please give me Solution 07-31 14:27:35.558: ERROR/AndroidRuntime(375): FATAL EXCEPTION: main 07-31 14:27:35.558: ERROR/AndroidRuntime(375): java.lang.NumberFormatException: unable to parse '' as integer 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at java.lang.Integer.parseInt(Integer.java:412) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at java.lang.Integer.parseInt(Integer.java:382) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at com.ExtraCharge.Calc.onClick(Calc.java:744) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.view.View.performClick(View.java:2408) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.view.View$PerformClick.run(View.java:8816) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.os.Handler.handleCallback(Handler.java:587) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:92) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:123) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:521) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-31 14:27:35.558: ERROR/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method)

A: 

You are converting the value of the text-field three times:

   temp_val = Double.parseDouble(et1.getText().toString());
   ...
   String temp_val1=Double.toString(temp_val);
   wbval = Integer.parseInt(temp_val1);

why do you do that? That wont work very well because if temp_val holds a double, then temp_val1 will hold a double, and the last conversation will fail. That is what happens, but:

In fact, temp_val1 holds an empty string, that's why the exception is thrown at the last conversation.

theomega