java - Having converting and getting data problems -


i wrote program calculates acceleration. how looks:

http://prntscr.com/57yngo

when press button show dialog message part of joptionpane. data enter in fields strings convert them double doing :

double name = double.valueof(string);

the problem if inserted string value instead of double value in fields , pressed button sends acceleration total program badly crash. need solution fix that!

if said why did set inserted value string answer way

textfieldname.gettext();

if knew way double text field please tell me it.

try this:

public static void main(string[] args) {     string[] values = {"1.0", "2.0", "a"};     (string value: values) {         system.out.println(getvalue(value));     } }  private static double getvalue(string valuestring) {     double result;     try {         result = double.valueof(valuestring);     } catch (numberformatexception e) {         result = 0.0;     }     return result; } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -