如何将 String 转换为 int 并在其上调用方法?

问题描述

我曾尝试将我的 String 转换为 int,但我的代码一直崩溃。

代码如下:

String age = getAge();
CalculateDaysSinceBirth((int) age);

但我得到一个 NumberFormatException

解决方法

尝试使用 Integer.valueOf(age) 插入的 (int) age