eclipse上的控制台没有显示任何内容

时间:2013-12-25 04:10:38

标签: java eclipse math console

我尝试在eclipse上运行Java代码。有像“system.out.print”这样的代码但是当我按下运行时控制台显示这个......

java.lang.String的值布局无效

Java Runtime Environment检测到致命错误:

内部错误(javaClasses.cpp:136),pid = 2276,tid = 2148

致命错误:预加载类的布局无效

JRE版本:(7.0_45-b18)(构建)

Java VM:Java HotSpot(TM)64位服务器VM(24.45-b08混合模式windows-amd64压缩oops)

无法编写核心转储。默认情况下,在Windows的客户端版本

上未启用小型转储

包含更多信息的错误报告文件保存为: C:\用户\管理员\工作区\当前\当前\ hs_err_pid2276.log

如果您想提交错误报告,请访问:

http://bugreport.sun.com/bugreport/crash.jsp

如何解决它。请帮帮我。这是我尝试运行的代码......

import Jama.Matrix;
import Jama.QRDecomposition;


public class LeastSquare {
private final int N;         // number of observations
private final int degree;    // degree of the polynomial regression
private final Matrix beta;   // the polynomial regression coefficients
private double SSE;          // sum of squares due to error
private double SST;          // total sum of squares


public LeastSquare(double[] x, double[] y, int degree) {
    this.degree = degree;
    N = x.length;

    // build Vandermonde matrix
    double[][] vandermonde = new double[N][degree+1];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= degree; j++) {
            vandermonde[i][j] = Math.pow(x[i], j);
        }
    }
    Matrix X = new Matrix(vandermonde);

    // create matrix from vector
    Matrix Y = new Matrix(y, N);

    // find least squares solution
    QRDecomposition qr = new QRDecomposition(X);
    beta = qr.solve(Y);


    // mean of y[] values
    double sum = 0.0;
    for (int i = 0; i < N; i++)
        sum += y[i];
    double mean = sum / N;

    // total variation to be accounted for
    for (int i = 0; i < N; i++) {
        double dev = y[i] - mean;
        SST += dev*dev;
    }

    // variation not accounted for
    Matrix residuals = X.times(beta).minus(Y);
    SSE = residuals.norm2() * residuals.norm2();
}


public double beta(int j) {
    return beta.get(j, 0);
}


public int degree() {
    return degree;
}


public double R2() {
    if (SST == 0.0) return 1.0;   // constant function
    return 1.0 - SSE/SST;
}


public double predict(double x) {
    // horner's method
    double y = 0.0;
    for (int j = degree; j >= 0; j--)
        y = beta(j) + (x * y);
    return y;
}


public String toString() {
    String s = "";
    int j = degree;

    // ignoring leading zero coefficients
    while (j >= 0 && Math.abs(beta(j)) < 1E-5)
        j--;

    // create remaining terms
    for (j = j; j >= 0; j--) {
        if      (j == 0) s += String.format("%.2f ", beta(j));
        else if (j == 1) s += String.format("%.2f N + ", beta(j));
        else             s += String.format("%.2f N^%d + ", beta(j), j);
    }
    return s + "  (R^2 = " + String.format("%.3f", R2()) + ")";
}

public static void main(String[] args) {
    double[] x = { 10, 20, 40, 80, 160, 200 };//
    double[] y = { 100, 350, 1500, 6700, 20160, 40000 };
    LeastSquare regression = new LeastSquare(x, y, 3);
    System.out.println(regression);
}

}

2 个答案:

答案 0 :(得分:0)

在我看来你的toString函数可能不起作用,当你执行System.out.println(...)试试这个

System.out.println(regression.toString());

如果这不能解决问题,那么设置字符串以从toString()返回时很可能出现问题

答案 1 :(得分:0)

jamolnng几乎回答了你的问题。我遇到过那个问题一次。 你的项目是Maven构建的吗? 如果是这样,请尝试: 从右键单击项目中删除maven性质 - &gt; Maven - &gt; Diasble Maven Nature。  转到您的终端/命令并从项目目录“mvn clean install”

传递它

转到IDE并进行Build-Clean(项目) 并且可以实现Maven Nature项目。

尝试运行&amp;看看是否有帮助。