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 5949179
In Process

The Archive Base Latest Questions

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

I have this code to display my file into JTable but I have an

  • 0

I have this code to display my file into JTable but I have an error

array required, but java.lang.Object found

Here is my code:

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.*;
import java.util.*;


public class TableDemo extends JPanel {
    private boolean DEBUG = false;
    static ArrayList rosterList = new ArrayList();   // added static infront becuase got non static referencing error

    public TableDemo() {
        super(new GridLayout(1,0));

        JTable table = new JTable(new MyTableModel());
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);

        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this panel.
        add(scrollPane);
    }

    class MyTableModel extends AbstractTableModel {
        private String[] columnNames = { "Κωδικός", "Ποσότητα", "Τιμή", "Περιγραφή", "Μέγεθος", "Ράτσα"};


        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return rosterList.size();
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

     public Object getValueAt(int row, int col)
        {
             return rosterList.get(row)[col];  //array required,but java.lang.Object found

        }


    }


    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("TableDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        TableDemo newContentPane = new TableDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                creatArr();
                createAndShowGUI();

            }
        });
    }


private static void creatArr()
  {
     BufferedReader br = null;

     try
    {
      br = new BufferedReader(new FileReader("Dogss.txt"));
      String line = br.readLine();

      while (line != null )
      {
        String [] rowfields = line.split("#");
        rosterList.add(rowfields);
        line = br.readLine();
       }

    }
    catch (FileNotFoundException e)
    {
      // can be thrown when creating the FileReader/BufferedReader
      // deal with the exception
      e.printStackTrace();
    }
    catch (IOException e)
    {
      // can be thrown by br.readLine()
      // deal with the exception
      e.printStackTrace();
    }


}




}
  • 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-22T17:12:46+00:00Added an answer on May 22, 2026 at 5:12 pm

    Java doesn’t know that your list contains array of String.

    you should declare rosterList like this:

    static ArrayList<String[]> rosterList = new ArrayList<String[]>();
    

    or even better:

    static List<String[]> rosterList = new ArrayList<String[]>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code I'm trying to get to display but no
I have the following code where i save the xml file into this particular
I have this code that performs an ajax call and loads the results into
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
I have this code, which works fine, but I would like to be able
i have problem to store image into sd car, there are not display file
I have swf file, im using code below to display it on my website:
So I have found this code here This basically lets me pull some data
I have the following code to import a delimited file into an Access 2003
I have the following code. (You can copy it into a file to debug

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.