I am working on an application in Eclpise and this is the only place I could think of where I could get help. Here is the code in the class affected:
This is the error message:
Tell me if you need code from classes that work with this one.
Thanks!!
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; public class Main extends JFrame { Class newClass; JTabbedPane tab; JPanel panel1; JTabbedPane tabbedPane=new JTabbedPane(); int numberStudents; String numberOfStudents; JPanel topPanel = new JPanel(); public int classOffset=0; ArrayList<Class> newClasses=new ArrayList(); public Main() { super("Grading System"); setSize(400, 500); setBounds(600,300,400,550); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add(topPanel); newClass(); JToolBar bar=new JToolBar(); JButton addClass=new JButton("class"); addClass.setIcon(new ImageIcon(getClass().getResource("/plus.png"))); addClass.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { newClass(); //JOptionPane.showMessageDialog(null, String.valueOf(selected)); } } ); bar.add(addClass); pane.add("North",bar); add("North",bar); setVisible(true); } private void FileManager(String string, String noOfStudents) { // TODO Auto-generated method stub } public static void main(String[] args) { Main main=new Main(); } public void actionPerformed(ActionEvent e) { Main newClass=new Main(); JOptionPane.showMessageDialog(null, String.valueOf(213124)); } public void newClass() { File f = new File("H:/marker"); f.mkdirs(); try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } String buttonText[]={"Choose","Make"}; int response = JOptionPane.showOptionDialog(null, "Do you wish to choose a class, or make a new one?", "Option Dialouge", 0, JOptionPane.INFORMATION_MESSAGE,null,buttonText,buttonText[0]); if(response==1) { String nameOfClass = JOptionPane.showInputDialog(null, "What do you want to name this class?", JOptionPane.QUESTION_MESSAGE); String noOfStudents = JOptionPane.showInputDialog(null, "How many students are in the class?", JOptionPane.QUESTION_MESSAGE); FileManager("H:\\marker\\classes\\"+nameOfClass+"\\settings.txt",noOfStudents); newClass=new Class("H:\\marker\\classes\\"+nameOfClass,nameOfClass,noOfStudents); tabbedPane = new JTabbedPane(); tabbedPane.addTab( newClass.returnName(), newClass ); topPanel.add( tabbedPane, BorderLayout.CENTER ); setVisible(true); add(topPanel); } else if(response==0) { FileManager fm = new FileManager("H:\\marker\\classes"); Class newClass = null; newClasses.add(classOffset,newClass); //newClasses.add(newClass); while(newClasses.get(classOffset)==null) { if(fm.getState()==1){ classOffset+=1; try { //numberOfStudents=new String(Files.readAllBytes(Paths.get("H:\\marker\\classes\\"+fm.getSelectedOption()+"\\settings.txt"))); } catch (Exception e) {e.printStackTrace();} int temp=10; newClass=new Class("H:\\marker\\classes\\"+fm.getSelectedOption(),fm.getSelectedOption(),temp); fm.dispose(); tabbedPane.addTab( newClass.returnName(), newClass ); topPanel.add(tabbedPane, BorderLayout.CENTER); setVisible(true); add(topPanel); } } } } }
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at Main.newClass(Main.java:92) at Main.<init>(Main.java:32) at Main.main(Main.java:57)