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!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 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); } } } } } |
1 2 3 4 5 6 | 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 ) |