after compiling it this errors came out, what do u think is the possible solution for this?
thanks!

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9
at accountinfo.<init>(Main.java:73)
at accountinfo.main(Main.java:142)

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

 class accountinfo implements ActionListener
{

	private JFrame f3;
	private JButton jLogout;
	private JPanel pn1, pn2, pn3, pn4, pn5, pn6, pn7, pn8, pn9;
	private JLabel fname, lname, add, mail, birth, myacc, gender, studno,
			fname1, lname1, add1, mail1, birth1, myacc1, gender1, studno1;

	private String[] text;

	public accountinfo()
	{
            	text = new String [9];
		try
		{
		String get1 = "abby1";

		FileReader fr = new FileReader("D:/Users/"+ get1 +".txt");
		BufferedReader in = new BufferedReader(fr);


		for(int x = 0; x < 9 ; x++)
		{
			text[x] = in.readLine();
		}
			}

		catch(FileNotFoundException e)
		{
			JOptionPane.showMessageDialog(null,"No Such File",
			"System Log", JOptionPane.ERROR_MESSAGE);
		}

		catch(IOException e)
		{
			System.out.print("not found");
		}


		f3 = new JFrame("Account Information");

		jLogout = new JButton("Log Out");
		jLogout.addActionListener(this);

		pn1 = new JPanel();
		pn2 = new JPanel();
		pn3 = new JPanel();
		pn4 = new JPanel();

		fname = new JLabel("First Name: ");
		lname = new JLabel("Last Name: ");
		add = new JLabel("Address: ");
		mail = new JLabel("Email Address: ");
		birth = new JLabel("Birthday: ");
		myacc = new JLabel("My Account");
		gender = new JLabel("Gender");
		studno = new JLabel("Student Number: ");

		fname1 = new JLabel(text[2]);
		lname1 = new JLabel(text[3]);
		add1 = new JLabel(text[4]);
		mail1 = new JLabel(text[5]);
		birth1 = new JLabel(text[6]);
		myacc1 = new JLabel(text[7]);
		gender1 = new JLabel(text[8]);
		studno1 = new JLabel(text[9]);


		myacc.setForeground(Color.darkGray);
		myacc.setFont(new Font("Arial Black", Font.BOLD, 15));
	}

	public void launch2()
	{
		pn1.setLayout(new FlowLayout());
		pn1.add(myacc);
		pn1.add(jLogout);

		pn2.setLayout(new FlowLayout());
		pn2.add(fname);
		pn2.add(fname1);

		pn3.setLayout(new FlowLayout());
		pn3.add(lname);
		pn3.add(lname1);

		pn4.setLayout(new FlowLayout());
		pn4.add(add);
		pn4.add(add1);

		pn5.setLayout(new FlowLayout());
		pn5.add(mail);
		pn5.add(mail1);

		pn6.setLayout(new FlowLayout());
		pn6.add(birth);
		pn6.add(birth1);

		pn7.setLayout(new FlowLayout());
		pn7.add(gender);
		pn7.add(gender1);

		pn8.setLayout(new FlowLayout());
		pn8.add(studno);
		pn8.add(studno1);

                f3.setLayout(new GridLayout(8,1));
		f3.add(pn1);
		f3.add(pn3);
		f3.add(pn2);
		f3.add(pn4);
		f3.add(pn5);
		f3.add(pn6);
		f3.add(pn7);
		f3.add(pn8);
		f3.setVisible(true);
		f3.pack();
		f3.setLocation(500,200);
		f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

       public void actionPerformed (ActionEvent event)
	{
		if(event.getActionCommand().equals("Log Out"))
		{

			//LogIn rf = new LogIn();
			//rf.launch();
			f3.dispose();
		}
	}

	public static void main(String[] args)
	{
		accountinfo l = new accountinfo();
		l.launch2();

	}

}

Recommended Answers

All 5 Replies

Your line nos seem 1 out from the error messages, but
studno1 = new JLabel(text[9]); is the line in question
text = new String [9]; is the size of "text"
so the valid array indexes for text are 0..8

i've tried changing the size of text to 10. unfortunately, a new error occur and I can't seem to identify the problem. here's the error message

Exception in thread "main" java.lang.NullPointerException
at accountinfo.launch2(Main.java:98)
at accountinfo.main(Main.java:143)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

you have these 4 lines:

pn1 = new JPanel();
pn2 = new JPanel();
pn3 = new JPanel();
pn4 = new JPanel();

but i see 8 panels or up to pn8. 4 are null so maybe that is the null pointer exception. I really hate to see variables like pn1 through pn8. that's where you use arrays.

Mike

oh my god! I can't believe i missed that.. thanks Adam161 and JamesCherrill. cheers! :)

and thanks for the suggestion about using arrays. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.