java.lang.IndexOutOfBoundsException:索引:6,大小:6 java,数组
我意识到这是一个难以置信的普遍问题,并且已经非常彻底地研究过了,但是没有运气!我似乎有一个边界外的例外问题。我的代码如下:刚刚出现错误!再次感谢:) 更新: 感谢您的快速回复。虽然它说AnalysisPanel有问题,但我不知道这是否是原因,因为我有其他类使用它时没有问题!但下面是另一个代码。再次感谢java.lang.IndexOutOfBoundsException:索引:6,大小:6 java,数组,java,arrays,Java,Arrays,我意识到这是一个难以置信的普遍问题,并且已经非常彻底地研究过了,但是没有运气!我似乎有一个边界外的例外问题。我的代码如下:刚刚出现错误!再次感谢:) 更新: 感谢您的快速回复。虽然它说AnalysisPanel有问题,但我不知道这是否是原因,因为我有其他类使用它时没有问题!但下面是另一个代码。再次感谢 public class AnalysisPanel extends JPanel { private JTextArea overview_text = GuiComponentGenerat
public class AnalysisPanel extends JPanel {
private JTextArea overview_text = GuiComponentGenerator.getJTextArea("");
private JTextArea csv_text = GuiComponentGenerator.getJTextArea("");
private JComboBox analyser_choices;
private String[] analyser_class_names;
private LinkedHashMap<String, ImageAnalysis> analyser_outputs = new LinkedHashMap();
private JTextField[] weka_directory_texts;
private JTextField[] weka_tag_texts;
private JTextField weka_output_file_path_text = GuiComponentGenerator
.getJTextField("");
private JTextField weka_relation_text = GuiComponentGenerator
.getJTextField("");
public AnalysisPanel() {
GuiComponentGenerator.setLook(this);
analyser_class_names = ResourceAndClassDirectories
.getClassNamesInDirectory(ResourceAndClassDirectories.IMAGE_ANALYSERS_CLASS_STEM);
ArrayList<String> choices = new ArrayList(
Arrays.asList(analyser_class_names));
choices.add(0, "All");
analyser_choices = GuiComponentGenerator.getJComboBox(choices);
analyser_choices.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateTextBoxes();
}
});
setLayout(new BorderLayout());
add(BorderLayout.NORTH,
GuiComponentGenerator.getJPanel(analyser_choices));
add(BorderLayout.CENTER, getTextsPanel());
add(BorderLayout.SOUTH, getWekaPanel());
}
private JPanel getWekaPanel() {
JPanel weka_panel = GuiComponentGenerator.getJPanel(new BorderLayout());
JPanel details_panel = GuiComponentGenerator.getJPanel(new GridLayout(
6, 1));
JPanel top_panel = GuiComponentGenerator
.getJPanel(new GridLayout(1, 2));
JPanel left_top_panel = GuiComponentGenerator.getJPanel(new BorderLayout());
JPanel right_top_panel = GuiComponentGenerator.getJPanel(new BorderLayout());
left_top_panel.add(BorderLayout.WEST, GuiComponentGenerator.getJLabel("Relation:"));
left_top_panel.add(BorderLayout.CENTER, weka_relation_text);
right_top_panel.add(BorderLayout.WEST, GuiComponentGenerator.getJLabel("Output to:"));
right_top_panel.add(BorderLayout.CENTER, weka_output_file_path_text);
top_panel.add(left_top_panel);
top_panel.add(right_top_panel);
weka_panel.add(BorderLayout.NORTH, top_panel);
weka_directory_texts = new JTextField[5];
weka_tag_texts = new JTextField[5];
JPanel labels_panel = GuiComponentGenerator.getJPanel(new GridLayout(1,
2));
labels_panel.add(GuiComponentGenerator.getCentreAlignedJLabel("Tag"));
labels_panel.add(GuiComponentGenerator
.getCentreAlignedJLabel("Image directory"));
details_panel.add(labels_panel);
for (int pos = 0; pos < 5; pos++)
details_panel.add(getDetailsPanel(pos));
weka_panel.add(BorderLayout.NORTH, top_panel);
weka_panel.add(BorderLayout.CENTER, details_panel);
JPanel weka_bordered_panel = GuiComponentGenerator
.getLeftBorderedJPanel(weka_panel, "Weka");
return weka_bordered_panel;
}
private JPanel getDetailsPanel(int pos) {
JPanel details_panel = GuiComponentGenerator.getJPanel(new GridLayout(
1, 2));
final JTextField weka_directory_text = GuiComponentGenerator
.getJTextField("");
JTextField weka_tag_text = GuiComponentGenerator.getJTextField("");
weka_directory_texts[pos] = weka_directory_text;
weka_tag_texts[pos] = weka_tag_text;
JPanel right_panel = GuiComponentGenerator
.getJPanel(new BorderLayout());
right_panel.add(BorderLayout.CENTER, weka_directory_text);
JButton choose_directory_button = GuiComponentGenerator
.getJButton(GuiComponentGenerator.FILE_DIALOG_ICON);
right_panel.add(BorderLayout.EAST, choose_directory_button);
choose_directory_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
File directory = FileChooserDialog.getFile(
ResourceAndClassDirectories.SOURCE_DIRECTORY, "", true);
if (directory != null)
weka_directory_text.setText(directory.getPath());
}
});
details_panel.add(weka_tag_text);
details_panel.add(right_panel);
return details_panel;
}
public String[] getWekaRunDetails() {
String[] wrd = { weka_relation_text.getText(),
weka_output_file_path_text.getText() };
return wrd;
}
public ArrayList<String[]> getWekaImageDetails() {
ArrayList<String[]> image_details = new ArrayList();
for (int pos = 0; pos < 5; pos++) {
String[] details = { weka_directory_texts[pos].getText(),
weka_tag_texts[pos].getText() };
image_details.add(details);
}
return image_details;
}
private JPanel getTextsPanel() {
JPanel texts_panel = GuiComponentGenerator
.getJPanel(new BorderLayout());
csv_text.setRows(3);
csv_text.setFont(new Font("Courier", Font.PLAIN, 14));
texts_panel.add(BorderLayout.NORTH, GuiComponentGenerator
.getLeftBorderedJPanel(
GuiComponentGenerator.getJScrollPane(csv_text), "CSV"));
texts_panel.add(BorderLayout.CENTER, GuiComponentGenerator
.getLeftBorderedJPanel(
GuiComponentGenerator.getJScrollPane(overview_text),
"Overview"));
return texts_panel;
}
public String getChosenImageAnalyser() {
return (String) analyser_choices.getSelectedItem();
}
public void performAnalyses(final TaggedBufferedImage tbi) {
Thread thread = new Thread() {
public void run() {
analyser_outputs.clear();
String choice = (String) analyser_choices.getSelectedItem();
csv_text.setText("");
if (choice.equals("All")) {
for (String analyser_class_name : analyser_class_names)
performAnalysis(analyser_class_name, tbi);
} else
performAnalysis(choice, tbi);
updateTextBoxes();
}
};
thread.start();
}
private void updateTextBoxes() {
String overview = "";
String csv_headings = "|";
String csv_values = "|";
String choice = (String) analyser_choices.getSelectedItem();
for (String analyser_class_name : analyser_class_names) {
if (choice.equals("All") || choice.equals(analyser_class_name)) {
ImageAnalysis image_analysis = analyser_outputs
.get(analyser_class_name);
if (image_analysis != null) {
overview += analyser_class_name + "\n\n"
+ image_analysis.overview + "\n-----------------\n";
System.out.println("In Analysis Panel: image analsis csv headings " + image_analysis.csv_headings.size());
for (int pos = 0; pos < image_analysis.csv_headings.size(); pos++) {
String heading = image_analysis.csv_headings.get(pos);
String value = image_analysis.csv_values.get(pos);
while (heading.length() < value.length())
heading += " ";
while (value.length() < heading.length())
value += " ";
csv_values += value + "|";
csv_headings += heading + "|";
}
}
}
}
overview_text.setText(overview);
csv_text.setText(csv_headings + "\n" + csv_values);
}
private void performAnalysis(String analyser_class_name,
TaggedBufferedImage tbi) {
try {
overview_text.setText("Analysing " + analyser_class_name);
Class c = Class
.forName(ResourceAndClassDirectories.IMAGE_ANALYSERS_CLASS_STEM
+ "." + analyser_class_name);
ImageAnalyserInterface analyser = (ImageAnalyserInterface) c
.newInstance();
ImageAnalysis image_analysis = analyser.analyseImage(tbi);
analyser_outputs.put(analyser_class_name, image_analysis);
} catch (Exception ex) {
ex.printStackTrace();
}
}
公共类分析面板扩展了JPanel{
私有JTextArea overview_text=GuiComponentGenerator.getJTextArea(“”);
私有JTextArea csv_text=GuiComponentGenerator.getJTextArea(“”);
私人JComboBox分析器_选项;
私有字符串[]分析器类名称;
私有LinkedHashMap分析器_输出=新LinkedHashMap();
私有JTextField[]weka_目录_文本;
私有JTextField[]weka_标签_文本;
私有JTextField weka_输出_文件_路径_text=GuiComponentGenerator
.getJTextField(“”);
私有JTextField weka_relation_text=GuiComponentGenerator
.getJTextField(“”);
公共事务委员会(){
GuiComponentGenerator.setLook(this);
Analyzer\u class\u names=资源和类目录
.getClassNamesInDirectory(ResourceandClassDirectory.IMAGE\u Analyzers\u CLASS\u STEM);
ArrayList选项=新建ArrayList(
asList(分析器类名称);
选择。添加(0,“全部”);
Analyzer_choices=GuiComponentGenerator.getJComboBox(选项);
Analyzer_choices.addItemListener(新的ItemListener(){
公共无效itemStateChanged(ItemEvent e){
updateTextBox();
}
});
setLayout(新的BorderLayout());
添加(BorderLayout.NORTH、,
getJPanel(Analyzer_选项));
添加(BorderLayout.CENTER,getTextsPanel());
添加(BorderLayout.SOUTH,getWekaPanel());
}
私人JPanel getWekaPanel(){
JPanel-weka_panel=GuiComponentGenerator.getJPanel(newborderlayout());
JPanel details\u panel=GuiComponentGenerator.getJPanel(新的GridLayout(
6, 1));
JPanel top_panel=GUI组件生成器
.getJPanel(新网格布局(1,2));
JPanel left_top_panel=GuiComponentGenerator.getJPanel(newborderlayout());
JPanel right_top_panel=GuiComponentGenerator.getJPanel(newborderlayout());
左上面板。添加(BorderLayout.WEST,GuiComponentGenerator.getJLabel(“关系:”);
左上面板。添加(BorderLayout.CENTER,weka关系文本);
右上面板.add(BorderLayout.WEST,GuiComponentGenerator.getJLabel(“输出到:”);
右上面板。添加(BorderLayout.CENTER,weka\u输出\u文件\u路径\u文本);
顶部面板。添加(左侧顶部面板);
顶部面板。添加(右侧顶部面板);
weka_面板。添加(BorderLayout.NORTH,顶部面板);
weka_目录_文本=新的JTextField[5];
weka_tag_text=新的JTextField[5];
JPanel labels_panel=GuiComponentGenerator.getJPanel(新的GridLayout(1,
2));
labels_panel.add(GuiComponentGenerator.getCentreAlignedJLabel(“Tag”));
标签\u面板。添加(GUI组件生成器
.getcentralignedjlabel(“映像目录”);
详细信息面板。添加(标签面板);
用于(int pos=0;pos<5;pos++)
细节面板添加(getDetailsPanel(pos));
weka_面板。添加(BorderLayout.NORTH,顶部面板);
weka_面板。添加(BorderLayout.CENTER,details_面板);
JPanel weka_镶边_面板=GUI组件生成器
.getLeftBorderedJPanel(weka_小组,“weka”);
返回weka_镶边_面板;
}
私人JPanel getDetailsPanel(内部位置){
JPanel details\u panel=GuiComponentGenerator.getJPanel(新的GridLayout(
1, 2));
最终JTextField weka_directory_text=GuiComponentGenerator
.getJTextField(“”);
JTextField weka_tag_text=GuiComponentGenerator.getJTextField(“”);
weka_目录_文本[pos]=weka_目录_文本;
weka_标签_文本[pos]=weka_标签_文本;
JPanel右面板=GUI组件生成器
.getJPanel(新的BorderLayout());
右面板。添加(BorderLayout.CENTER,weka\u目录\u文本);
JButton choose_directory_button=GuiComponentGenerator
.getJButton(GuiComponentGenerator.FILE_对话框_图标);
右面板。添加(BorderLayout.EAST,选择目录按钮);
选择目录按钮。添加ActionListener(新建ActionListener(){
已执行的公共无效操作(操作事件arg0){
File directory=FileChooserDialog.getFile(
ResourceAndClassDirectory.SOURCE_目录,”,true);
if(目录!=null)
weka_directory_text.setText(directory.getPath());
}
});
详细信息面板。添加(weka标签文本);
详细信息面板。添加(右面板);
返回详细信息\u面板;
}
公共字符串[]getWekaRunDetails(){
字符串[]wrd={weka_relation_text.getText(),
weka_输出_文件_路径_text.getText()};
返回wrd;
}
公共阵列列表getWekaImageDetails(){
ArrayList image_details=新建ArrayList();
用于(int pos=0;pos<5;pos++){
String[]details={weka_目录_文本[pos].getText(),
weka_tag_text[pos].getText()};
图像_详细信息。添加(详细信息);
}
返回图像的详细信息;
}
私有JPanel getTextsPanel(){
JPanel text_panel=GuiComponentGenerator
.getJPanel(新的BorderLayout());
csv_text.setRows(3);
csv_text.setFont(新字体(“Courier”,Font.PLAIN,14));
文本面板添加(BorderLayout.NORTH,GUI组件生成器
.getLeftBorderedJPanel(
GuiComponentGenerator.getJScrollPane(csv_text),“csv”);
文本\u面板.add(BorderLayout.CENTER,GUI组件生成器
.getLeftBorderedJPanel(
GuiComponentGenerator.getJScrollPane(概述\u文本),
"概览");;
返回文本(U)面板;
}
公共字符串getChosenImageAnalyzer(){
返回(字符串)分析器_选项。getSelectedItem();
}
公共无效绩效分析(最终T