Can Anyone Tell Me How To Fix This?

Hi everyone, can anyone tell me what this error means:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Quiz.main(Quiz.java:22)
I got this error when I tried to run a quiz program, I downloaded it from the internet to see how it worked but I am now unable to run it, here is the code:
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
import java.awt.*;
public class Quiz
JButton answer1;
JButton answer2;
JButton answer3;
JButton answer4;
int numberCorrect = 0;
int numberIncorrect = 0;
int totalNumber = 0;
public static void main(String[] args)
JFrame frame = new JFrame("Spanish Quiz");
frame.getContentPane().add(new Quiz().create(args[0])); //I think error is here
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.pack();
frame.setVisible(true);
public Component create(String fileName)
JPanel pane = new JPanel();
try
BufferedReader in = new BufferedReader(new
FileReader(fileName));
boolean moreLines = true;
Vector lines = new Vector();
while (moreLines == true)
String currentLine = in.readLine();
if (currentLine == null)
moreLines = false;
break;
lines.addElement(currentLine);
for (int i = 0; i < lines.size() / 6; i = i + 6)
JLabel question = new JLabel((String)
lines.elementAt(i));
answer1 = new QuizButton (this, (String)
lines.elementAt(i + 1));
answer2 = new QuizButton (this, (String)
lines.elementAt(i + 2));
answer3 = new QuizButton (this, (String)
lines.elementAt(i + 3));
answer4 = new QuizButton (this, (String)
lines.elementAt(i + 4));
pane.setLayout(new GridLayout(5,1));
pane.add(question);
pane.add(answer1);
pane.add(answer2);
pane.add(answer3);
pane.add(answer4);
catch (Exception e)
return pane;
class QuizButton extends JButton implements ActionListener
JButton button;
String button_text;
Quiz m_quiz;
QuizButton (Quiz quiz, String text)
button_text = text;
m_quiz = quiz;
button = new JButton (button_text.substring(1));
public void actionPerformed(ActionEvent e)
JButton button = (JButton) e.getSource();
if (button_text.charAt (0) == '*') {
JOptionPane.showMessageDialog(null, "Correct");
m_quiz.numberCorrect ++;
m_quiz.totalNumber ++;
else
JOptionPane.showMessageDialog(null, "Incorrect");
m_quiz.numberIncorrect ++;
m_quiz.totalNumber ++;
button.removeActionListener (this);
I think that It expects a command line parameter - a file name to be more exact but I do not know what - Can anyone please tell me
Thanks everyone

HI
The problem lies with the command line argument.Your program uses command line arguments( args[0] ), provide some arguments to it.
Secondly ArrayIndexOutOfBoundsException occurs if you are trying to access an element of array which does not exist i.e
if you have an array of say 5 elements i.e arr[5]
and you are trying to access 6th element which does not exist as your array contains only 5 elements.Try to check the size of array which you are using in the code.
Deepak
[email protected]

Similar Messages

Maybe you are looking for

  • How many use more than 1 smartphone

    I home office and have a Verizon BlackBerry for work and until today when I got my new Iphone 4 was using the Iphone 3G for personal use. I keep them side by side all day and can honestly say I have had quite a few dropped calls with my BB and could

  • Getting Podcast off Apple TV

    I just bought an Apple TV 160gb, works great but I am not able to figure out how to move a downloaded Podcast that I downloaded onto my Apple TV to my iTunes on my laptop. I also have a new iTouch that I workout with and I'd like to listen to the Pod

  • Authorization of Organizational elements at user level

    Sir, Is there any way by which I can assign organisational elments like-plant,company code,etc. to user id instead of Role? Thanks & regards, Sachin Taware 9920290697

  • How do I fix error 4001

    How do I fix error 4001 in itunes?

  • Profile - how to switch

    I've had my AX all of 12 hours now and of course been playing with it. I got it to join my home network and stream music to the stereo with no problems. I was trying to set up a profile so I could use it when traveling so it would do a direct connect