我需要能够将数组分配给.txt文件,因此我需要在while循环之外引用变量“s”。即使我定义并初始化变量后,我在while循环中初始化时仍然会出错。我做错了什么?
package vp.sga_form_generator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class GUI extends JFrame{
public GUI() throws FileNotFoundException {
super("SGA Form Creator - Viper Productions");
setSize(1000,800);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(30, 2));
//Opens File
Scanner names = new Scanner(new File("names.txt"));
// String name1 = names.next();
String[] s;
while(names.hasNext()){
s = {names.next()};
}
JComboBox names1 = new JComboBox(s);
JComboBox names2 = new JComboBox(s);
add(names1);
add(names2);
}
}
答案 0 :(得分:0)