帮助我:线程“主”中的例外情况java.lang.ArrayIndexOutOfBoundsException [英] Help Me : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
本文介绍了帮助我:线程“主”中的例外情况java.lang.ArrayIndexOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我构建项目时,我的主课有问题..
我收到消息:
线程main中的异常java.lang.ArrayIndexOutOfBoundsException:0
at ocr.training.MnistTraining.main(MnistTraining.java:22)
Java结果:1
我的Java代码:
I have a problem with my main class when I build my project..
I get message :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ocr.training.MnistTraining.main(MnistTraining.java:22)
Java Result: 1
My Java code:
public class MnistTraining {
/*
* ARGS Organization:
* 0 -> Number of Train Images
* 1 -> Number of cells for HorizontalCelledProjection
* 2 -> Number of cells for VerticalCelledProjection
*/
public static void main(String[] args) throws IOException{
int numTrainImages = new Integer(args[0]);
double[][] actual = new double[numTrainImages][];
double[][] ideal = new double[numTrainImages][];
MnistManager m = new MnistManager(Config.MNIST_TRAIN_IMAGES, Config.MNIST_TRAIN_LABELS);
FeatureExtraction fe = FeatureExtractionBuilder
.create()
.children(new HorizontalCelledProjection(new Integer(args[1])),
new VerticalCelledProjection(new Integer(args[2])))
.build();
// Build Training Data
for(int i = 1; i <= numTrainImages; ++i) {
// Get Pixel Matrix
m.setCurrent(i);
int[][] image = m.readPixelMatrix();
fe.setPixelMatrix(image);
fe.compute();
// Add to Training Data
double[] idealVector = new double[Config.OUTPUT_NEURONS];
idealVector[m.readLabel()] = 1;
actual[i-1] = fe.getFeatureVector();
ideal[i-1] = idealVector;
}
int inputNeurons = fe.getFeatureVector().length;
int hiddenNeurons = (2/3) * inputNeurons;
NeuralNetwork nn = NeuralNetworkBuilder
.create()
.inputNeurons(inputNeurons)
.hiddenNeurons(hiddenNeurons)
.outputNeurons(Config.OUTPUT_NEURONS)
.build();
nn.trainNetwork(actual, ideal);
nn.persistNetwork();
}
}
这个问题:第22行>
This The problem: line 22
int numTrainImages = new Integer(args[0]);
发生了什么以及如何解决它,帮帮我...谢谢你
What happened and how to solve it, Help me... thank you
推荐答案
它只是意味着你的args
object不为null,但为空。您的入口点方法(main
)收到0个命令行参数。该怎么办?在索引数据之前检查数组的大小。
-SA
It simply means that yourargs
object is not null, but it is empty. Your entry-point method (main
) received 0 command-line arguments. What to do? Check for the size of the array before indexing it.
—SA
这篇关于帮助我:线程“主”中的例外情况java.lang.ArrayIndexOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文