我正在尝试捕获异常,并且不允许应用程序强制关闭。因此,我被试着去抓住,就像被打击一样:

try
{
  String[] words = message.split(" ");
  strBuilder.setLength(0);

  numberString = words[8];
  if (numberString.length() > 4)
  {
    numberString = numberString.substring((numberString.length() - 4));
  }

   if ((message.contains("return")))
   {
     amountString = words[0];
     amountString = amountString.replace(",", "");
     amountString = getFilter(message);
    }

   else
    {
      for (int i = 12; i < words.length; i++)
        {
         text = words[i];
         strBuilder.append(text + " ");
         str = strBuilder.toString();
        }

      amountString = words[1];
      amountString = amountString.replace(",", "");

      nameString = str;
    }

    Log.e("Value","= " + amountString + nameString + numberString);
}
catch (NotFoundException e)
{
   Log.e("ERROR","Value Not fetched");
}

}

我在一个for循环中尝试上面的代码…
但应用程序仍然崩溃,并在amountstring=getfilter(消息)中出错;
为什么会这样?
是否需要在amount=getfilter(message);?之前插入try-and-catch?

最佳答案

您只捕获了NotFoundException,但在您的代码执行过程中可能会发生其他异常,导致应用程序崩溃。所以试着抓住Exception来找出哪里出了问题。

10-07 16:32