I have a problem to share with you guys a I am trying to check if a string is not equal to nothing and it should be "." value a string if it pass it will do certain line code if not it simply print something but the problem is when i try to put value "." it crashes. So is there any way to fix this?
Here is my kotlin main activity file :
calculate.setOnClickListener {
if(((distance.text.toString().length >0) &&
(initalVelocity.text.toString().length>0) &&
(time.text.toString().length > 0)
) && (!((distance.equals(".")) &&
(initalVelocity.equals(".")) &&
(time.equals("."))))) {
val s = distance.text.toString().toDouble()
val u = initalVelocity.text.toString().toDouble()
val t = time.text.toString().toDouble()
val a = (((2* s))-(2*(u*t)))/(t*t)
answer.setText("answer $a m/(s)^2")
} else {
toast("Are u nuts !!!!")
}
LOG:
FATAL EXCEPTION: main
Process: com.a3.apurv.physicscalculator, PID: 16094
java.lang.NumberFormatException: For input string: "."
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:539)
at com.a3.apurv.physicscalculator.AccelerationIVActivity$onCreate$2.onClick(AccelerationIVActivity.kt:31)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)