BigInteger를 가져 와서 다른 BigInteger를 추가하는 데 문제가 있습니다.BigInteger가 null 포인터 예외를 throw합니다.
클래스로 선언 :
private BigInteger mTotientSum;
이 생성자에 완료 :
BigInteger mTotientSum = BigInteger.ZERO;
상대 방법에있어서 : 내가 얻을 출력은
BigInteger totientMultiplier = BigInteger.valueOf(mTotientMulitplier);
for (long i = 1; i <= mMaxNum; i++)
{
BigInteger j = BigInteger.valueOf(i);
System.out.println(j.toString());
BigInteger num = j.multiply(totientMultiplier);
System.out.println(num.toString());
BigInteger totient = calculateTotient(num);
System.out.println(totient);
mTotientSum = mTotientSum.add(totient); //This is line 113
System.out.println("Sum at" + i + " = " + mTotientSum.toString());
}
모든 제안은 관련 코드를 :
1
510510
17
16
16
Exception in thread "main" java.lang.NullPointerException
at Totient.run(Totient.java:113) (Note that line 113 is noted above.)
at Totient.main(Totient.java:131)
코드에 줄 번호를 추가하여 NPE의 원래 위치를 알려주십시오. –
그것은 이미 언급되었습니다 ... – claydiffrient
@EngineerDollery는'mTotientSum = mTotientSum.add (totient);'뒤에 코멘트를 봅니다. – Pshemo