Android 从字符串数组转换为双精度时出现NumberFormatException

Android 从字符串数组转换为双精度时出现NumberFormatException,android,numberformatexception,Android,Numberformatexception,我正在尝试将字符串转换为双精度字符串。我在很多情况下都能做到,但这一次,它给了我一个数字形式的感觉。这是代码 //strExpression = 2^3 (My Input in the editText) strExpression = edtxtExpression.getText().toString(); try { System.out.println("Inside Power case"); //expSplit is a String[] expSplit

我正在尝试将字符串转换为双精度字符串。我在很多情况下都能做到,但这一次,它给了我一个数字形式的感觉。这是代码

//strExpression = 2^3 (My Input in the editText)

strExpression = edtxtExpression.getText().toString();

try
{
   System.out.println("Inside Power case");
   //expSplit is a String[]
   expSplit = strExpression.split("^");
   double first = Double.parseDouble(expSplit[0]);
   System.out.println("First Number "+first);
   double second = Double.parseDouble(expSplit[1]);
   System.out.println("Second Number "+second);

   double result = Math.pow(first, second);
   System.out.println("Result "+result);
   edtxtExpression.setText(first+" ^ "+second+" = "+result);

}
catch (Exception e) {
    // TODO: handle exception
    Toast.makeText(this, e.getClass().toString(), 100).show();

}
例外情况:::

01-01 03:07:45.169: I/System.out(11287): Inside Power case
01-01 03:07:45.179: I/System.out(11287): class java.lang.NumberFormatException

我得到“内部电源”输出,但其他打印语句没有执行。哪里出错了?

^
是正则表达式中的保留字符,请尝试
\\^

expSplit = strExpression.split("\\^");

^
是正则表达式中的保留字符,请尝试
\\^

expSplit = strExpression.split("\\^");

捕获一个NumberFormatException并打印出与之相关的消息?不。我只是想知道,异常是什么。所以,我吃了烤面包。捕捉一个数字格式异常并打印出与之相关的消息?不。我只是想知道,异常是什么。所以,我吃了烤面包。