【发布时间】:2014-07-03 08:20:48
【问题描述】:
所以,我的应用程序因为“java.lang.NumberFormatException: Invalid int: “2160000000”而崩溃,据我了解,最大可能的整数是 2,147,483,647。所以,很明显它正在崩溃,因为我正在尝试 setProgress on具有太大 int 的 ProgressBar。
我的问题是:有办法解决这个问题吗? int 这么大,因为我将 DAYS、HOURS 和 MINUTES 转换为毫秒。 因此,当我输入任何大于 24 天、20 小时、31 分钟的值时,应用程序会崩溃。 (上面的任何东西都会创建一个太大而无法被 setProgress 接受的整数。)
但是,我需要最多可以输入 32 天,但我找不到任何方法可以绕过这个限制性参数到 CountDownTimer。我在下面发布了一些代码以及一些 LogCat 错误以获取补充信息。
非常感谢,伙计们!
根据时间戳计算计时器应位于何处的方法:
public int bsCalculation() LINE # 138
DateTime date = new DateTime();
long currentTime = date.getMillis();
long bsDiffInMillis;
if(bsTimeStamp==0) {
bsDiffInMillis = 0;
}
else {
bsDiffInMillis = currentTime - bsTimeStamp;
timeInputBs -= bsDiffInMillis;
}
int bsDiffInt = Integer.parseInt(String.valueOf(bsDiffInMillis));
int roundedDiffBs = (bsDiffInt + 500) / 1000 * 1000;
j += roundedDiffBs;
return j;
}
将输入从 EditText(s) 转换为 millis 的方法:
public static Long getMillisForCrafting(long daysPh, long hoursPh, long minutesPh) {
Locale.getDefault();
DateTime bs = new DateTime();
daysPulled = daysPh;
hoursPulled = hoursPh;
minutesPulled = minutesPh;
final long nowInMillis = bs.getMillis();
Long days = daysPulled * 86400000;
Long hours = hoursPulled * 3600000;
Long minutes = minutesPulled * 60000;
Long millisToAddToNow = days + hours + minutes;
Long futureDateInMillis = millisToAddToNow + nowInMillis;
Long millisFromDate = futureDateInMillis - nowInMillis;
return millisFromDate;
}
原木猫:
E/AndroidRuntime(2283): FATAL EXCEPTION: main
E/AndroidRuntime(2283): java.lang.NumberFormatException: Invalid int: "2160000000"
E/AndroidRuntime(2283): at java.lang.Integer.invalidInt(Integer.java:138)
E/AndroidRuntime(2283): at java.lang.Integer.parse(Integer.java:378)
E/AndroidRuntime(2283): at java.lang.Integer.parseInt(Integer.java:366)
E/AndroidRuntime(2283): at java.lang.Integer.parseInt(Integer.java:332)
E/AndroidRuntime(2283): at com.example.esomount.HomeActivity$bsTimer.onTick(HomeActivity.java:376)
E/AndroidRuntime(2283): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:124)
【问题讨论】:
-
您不需要展示 32 位精度的进步。只需使用更粗粒度的度量即可。
标签: java android android-progressbar