Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BigInteger抛出NoClassDefFoundError_Java_Noclassdeffounderror_Biginteger - Fatal编程技术网

Java BigInteger抛出NoClassDefFoundError

Java BigInteger抛出NoClassDefFoundError,java,noclassdeffounderror,biginteger,Java,Noclassdeffounderror,Biginteger,我试图解决一个代码高尔夫问题,但我遇到了一个意想不到的问题。看起来Java的BigInteger类抛出了一个NoClassDefFoundError。这是我的密码- import java.math.BigInteger; public class UnGolfed { int sum=0; BigInteger num = new BigInteger("0"); int left; UnGolfed(int i){ left=i; }

我试图解决一个代码高尔夫问题,但我遇到了一个意想不到的问题。看起来Java的BigInteger类抛出了一个NoClassDefFoundError。这是我的密码-

import java.math.BigInteger;

public class UnGolfed {
    int sum=0;
    BigInteger num = new BigInteger("0");
    int left;
    UnGolfed(int i){
        left=i;
    }
    public static void main(String[] args) {

        (new UnGolfed(Integer.parseInt("1"))).doIt();
    }

    void doIt() {
        for(int i=left;i>0;i--){
            sum+=getNextHappy(num=num.nextProbablePrime());
        }
        System.out.print(sum);  
    }

    int getNextHappy(BigInteger b) {
        try{
            String s = b.toString();
            int tSum=0;
            for(char c : s.toCharArray()){
                tSum+=(c-48)*(c-48);
            }
            if(tSum==1) return num.intValue();
            return getNextHappy(new BigInteger(tSum+""));
        }
        catch(StackOverflowError e){
            return getNextHappy(num=num.nextProbablePrime());
        }       
    }
}
如果你好奇的话,那就找一个密码高尔夫挑战,找到前N个快乐素数的和。当我运行它时,虽然我得到以下信息-

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class java.security.SecureRandom
    at java.math.BigInteger.getSecureRandom(BigInteger.java:875)
    at java.math.BigInteger.passesMillerRabin(BigInteger.java:898)
    at java.math.BigInteger.primeToCertainty(BigInteger.java:739)
    at java.math.BigInteger.nextProbablePrime(BigInteger.java:690)
    at UnGolfed.getNextHappy(UnGolfed.java:33)
    at UnGolfed.getNextHappy(UnGolfed.java:30)
    at UnGolfed.getNextHappy(UnGolfed.java:30)
    .....
    .....
    .....

注意:我知道这段代码有很多问题,可能会运行到无限循环中,并导致堆栈溢出错误等。请忽略这些,我以后会弄清楚的。我只是想知道为什么会出现这个NoClassDefFoundError

你是如何运行这段代码的?似乎是可编译和可运行的,尽管它有一些问题。@LuiggiMendoza在一个Eclipse项目中。首先。。。为什么在StackOverflowException的catch块中使用递归。。。好像在消防水管里灌满了酒精为什么要用BigInteger???除非是为了你的家庭作业,否则我不理解这种开销。使用int。它会导致你做很多不必要的操作。本页有一些提示。这是一个链接,所以我不敢将其作为答案发布。