尝试这个:
private class FactCalculator extends AsyncTask {
int number = 0;
public FactCalculator(int i) {
this.number =i;
}
@Override
protected BigInteger doInBackground(final Void... params){
try{
if(number>=0) {
BigInteger res = new BigInteger("1");
for (int i = number; i > 1; i--) {
res = res.multiply(BigInteger.valueOf(i));
}
return res;
}
} catch(Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(final BigInteger result) {
if (result != null) {
TextView text = (TextView)findViewById(R.id.resultTextView);
text.setText(result.toString());
}
}
}
像这样称呼它:
new FactCalculator(80000).execute();
注意 :-正如其他人在评论中指出的那样,可能是因为该值太大,可能存在内存问题,或者可能无法保存在String或TextView ,