Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:12:38+00:00 2026-05-22T01:12:38+00:00

Hello I want to display my txt file but probably something is wrong! Any

  • 0

Hello I want to display my txt file but probably something is wrong! Any help? Here is my code:

    public class Display  extends Items{

 public int countLines(String filename){
        int lines = 0; //mporei na metrhsei mexri "int" grammes (~2.1 dis grammes)
        try {
            // Open the file that is the first command line parameter
            FileInputStream fstream = new FileInputStream(filename);
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            //Read File Line By Line
            while ((strLine = br.readLine()) != null) {
                lines++;//metrhths grammwn/eggrafwn
            }
            //close input stream
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

    return lines;}

 public String[] showAllRegisteredLessons(String filename, int size) {

        String[] temp = new String[size+1]; //mexri "size" kataxwrhseis ma8hmatwn dld (mege8os "int")

        try {
            int x = 0;
            // Open the file that is the first command line parameter
            FileInputStream fstream = new FileInputStream(filename);
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            //Read File Line By Line

            while ((strLine = br.readLine()) != null) {
                //System.out.println(strLine.replace("#", " "));
                temp[x] = strLine;
                x++;
            }
            //close input stream
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
        return temp;
    }

    public JPanel pinakas(String[] pinaka) {
        int sr = 0;
        //int ari8mos  =0;

        String[] COLUMN_NAMES = {"Κωδικός", "Ποσότητα", "Τιμή", "Περιγραφή", "Μέγεθος", "Ράτσα"};
//pio panw mporoume na pros8esoume ws prwto column to "#", wste na deixnei ton ari8mo ths ka8e kataxwrhshs
        DefaultTableModel modelM = new DefaultTableModel(COLUMN_NAMES, 0);
        JTable tableM = new JTable(modelM);
        JPanel mainPanel = new JPanel(new BorderLayout());
        mainPanel.add(new JScrollPane(tableM), BorderLayout.CENTER);

        Display disp = new Display();
        while (pinaka[sr] != null) // !!!!tha ektupwsei kai mia parapanw "/n" logo ths kataxwrhshs prwtou h teleytaiou mahmatos
        {
            String[] temp5 = disp.lineDelimiter(pinaka[sr],6, "#");
            Object[] doge = { temp5[0], temp5[1], temp5[2], temp5[3], temp5[4], temp5[5],temp5[6]};//edw mporoume sthn arxh na valoume to ari8mos gia na fainetai o ari8mos twn kataxwrhsewn
            modelM.addRow(doge);
            sr++;
            //ari8mos++;
        }

        return mainPanel;
    }

and in main()

 if(category31=="ΣΚΥΛΟΙ"){
                    Display disp= new Display();

                    int numberofline=disp.countLines("Dogss.txt");
                    String[] tempΜ1 = disp.showAllRegisteredLessons("Dogss.txt",numberofline);
                    //System.out.println(numberofline);

                    JOptionPane.showMessageDialog(null, disp.pinakas(tempΜ1), "Καταχωρημένα Kατοικίδια", JOptionPane.PLAIN_MESSAGE);

                     break;
                    }

I get this error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
        at program.Display.pinakas(Display.java:83)
        at program.Main.main(Main.java:334)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:12:39+00:00Added an answer on May 22, 2026 at 1:12 am

    I bet the problem is in the following lines (which is probably line 83..):

     String[] temp5 = disp.lineDelimiter(pinaka[sr],6, "#");
     Object[] doge = { temp5[0], temp5[1], temp5[2], temp5[3], temp5[4], temp5[5],temp5[6]};
    

    The array has only 6 elements. But you are accessing the 7th element with:

    temp5[6]
    

    That’s why you get the ArrayIndexOutOfBoundsException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably missing something simple here, but I can't find the answer elsewhere. I
I want to display Hello World with calibri.ttf using only AC3. How would I
I want to display the string Hello in the TextBlock. If the Culture is
I want to display "hello" message for 3 minutes and after that it should
hello i build a webservice to communicate with the iPhone. i want to display
Hello i have a website and a blog, i want to display my self
Hello I just want to display a drop down menu to choose the time
HEllo, I want to know how can I display the special characters in UILabel
I want to display on my website something similar to google maps transit directions,
Hello I want to read output of command which gives progress bar like output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.