jTable data problem

jTable data problem

Hello. I have a code that read file and store in arraylist and then convert to array(To use for table model)

My class extends abstracttablemodel correctly.

My All Code is:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class ReadFileToList extends AbstractTableModel{
String[] col={"Fname","Lname","Number"};
List<String> data=new ArrayList<String>();
String[][] Arraydata;
public void readtolist() throws IOException{
    FileReader fr=new FileReader("D:\\AllUserRecords.txt");
    BufferedReader br=new BufferedReader(fr);
    String line;
    while((line=br.readLine()) !=null){
        data.add(line);
        System.out.println(line);
    }
    br.close();
    Arraydata=(String[][]) data.toArray();
}

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

public int getRowCount() {
    return Arraydata.length;
}

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

public Object getValueAt(int rowIndex, int columnIndex) {
    return Arraydata[rowIndex][columnIndex];
}
}

My main Class is ReadFileToListM:

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class ReadFileToListM  {
ReadFileToList rftl=new ReadFileToList();
public ReadFileToListM(){
    JFrame frame=new JFrame();
    JTable table=new JTable(rftl);
    JPanel panel=new JPanel();
    JScrollPane sp=new JScrollPane(table);
    panel.add(sp);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(470,470);
    frame.setVisible(true);
}

public static void main(String[] args){
    new ReadFileToListM();
}
}

but it has Exception! Please help me, Thanks.

this is my Exceptions:

Exception in thread "main" java.lang.NullPointerException
    at Library.ReadFileToList.getRowCount(ReadFileToList.java:30)
    at javax.swing.JTable.getRowCount(JTable.java:2583)
    at javax.swing.plaf.basic.BasicTableUI.createTableSize(BasicTableUI.java:1646)
    at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1687)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1632)
    at javax.swing.JViewport.getViewSize(JViewport.java:1018)
    at javax.swing.ScrollPaneLayout.preferredLayoutSize(ScrollPaneLayout.java:476)
    at java.awt.Container.preferredSize(Container.java:1616)
    at java.awt.Container.getPreferredSize(Container.java:1601)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1634)
    at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594)
    at java.awt.Container.layout(Container.java:1432)
    at java.awt.Container.doLayout(Container.java:1421)
    at java.awt.Container.validateTree(Container.java:1519)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validate(Container.java:1491)
    at java.awt.Window.show(Window.java:820)
    at java.awt.Component.show(Component.java:1419)
    at java.awt.Component.setVisible(Component.java:1372)
    at java.awt.Window.setVisible(Window.java:801)
    at Library.ReadFileToListM.<init>(ReadFileToListM.java:20)
    at Library.ReadFileToListM.main(ReadFileToListM.java:24)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Library.ReadFileToList.getRowCount(ReadFileToList.java:30)
    at javax.swing.JTable.getRowCount(JTable.java:2583)
    at javax.swing.plaf.basic.BasicTableUI.createTableSize(BasicTableUI.java:1646)
    at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1687)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1632)
    at javax.swing.JViewport.getViewSize(JViewport.java:1018)
    at javax.swing.ScrollPaneLayout.preferredLayoutSize(ScrollPaneLayout.java:476)
    at java.awt.Container.preferredSize(Container.java:1616)
    at java.awt.Container.getPreferredSize(Container.java:1601)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1634)
    at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594)
    at java.awt.Container.layout(Container.java:1432)
    at java.awt.Container.doLayout(Container.java:1421)
    at java.awt.Container.validateTree(Container.java:1519)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validateTree(Container.java:1526)
    at java.awt.Container.validate(Container.java:1491)
    at java.awt.Window.dispatchEventImpl(Window.java:2427)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
 BUILD STOPPED (total time: 4 seconds)

I have a code that read file and store in arraylist and then convert to array(To use for table model)

My class extends abstracttablemodel correctly.

My All Code is:

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.table.AbstractTableModel;

public class ReadFileToList extends AbstractTableModel{ String[] col={"Fname","Lname","Number"}; List<String> data=new ArrayList<String>(); String[][] Arraydata; public void readtolist() throws IOException{ FileReader fr=new FileReader("D:\AllUserRecords.txt"); BufferedReader br=new BufferedReader(fr); String line; while((line=br.readLine()) !=null){ data.add(line); System.out.println(line); } br.close(); Arraydata=(String[][]) data.toArray(); }

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

public int getRowCount() { return Arraydata.length; }

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

public Object getValueAt(int rowIndex, int columnIndex) { return Arraydata[rowIndex][columnIndex]; } }

My main Class is ReadFileToListM:

import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable;

public class ReadFileToListM { ReadFileToList rftl=new ReadFileToList(); public ReadFileToListM(){ JFrame frame=new JFrame(); JTable table=new JTable(rftl); JPanel panel=new JPanel(); JScrollPane sp=new JScrollPane(table); panel.add(sp); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXITONCLOSE); frame.setSize(470,470); frame.setVisible(true); }

public static void main(String[] args){ new ReadFileToListM(); } }

but it has Exception! Please help me, Thanks.

this is my Exceptions:

Exception in thread "main" java.lang.NullPointerException at Library.ReadFileToList.getRowCount(ReadFileToList.java:30) at javax.swing.JTable.getRowCount(JTable.java:2583) at javax.swing.plaf.basic.BasicTableUI.createTableSize(BasicTableUI.java:1646) at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1687) at javax.swing.JComponent.getPreferredSize(JComponent.java:1632) at javax.swing.JViewport.getViewSize(JViewport.java:1018) at javax.swing.ScrollPaneLayout.preferredLayoutSize(ScrollPaneLayout.java:476) at java.awt.Container.preferredSize(Container.java:1616) at java.awt.Container.getPreferredSize(Container.java:1601) at javax.swing.JComponent.getPreferredSize(JComponent.java:1634) at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594) at java.awt.Container.layout(Container.java:1432) at java.awt.Container.doLayout(Container.java:1421) at java.awt.Container.validateTree(Container.java:1519) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validate(Container.java:1491) at java.awt.Window.show(Window.java:820) at java.awt.Component.show(Component.java:1419) at java.awt.Component.setVisible(Component.java:1372) at java.awt.Window.setVisible(Window.java:801) at Library.ReadFileToListM.(ReadFileToListM.java:20) at Library.ReadFileToListM.main(ReadFileToListM.java:24) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Library.ReadFileToList.getRowCount(ReadFileToList.java:30) at javax.swing.JTable.getRowCount(JTable.java:2583) at javax.swing.plaf.basic.BasicTableUI.createTableSize(BasicTableUI.java:1646) at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1687) at javax.swing.JComponent.getPreferredSize(JComponent.java:1632) at javax.swing.JViewport.getViewSize(JViewport.java:1018) at javax.swing.ScrollPaneLayout.preferredLayoutSize(ScrollPaneLayout.java:476) at java.awt.Container.preferredSize(Container.java:1616) at java.awt.Container.getPreferredSize(Container.java:1601) at javax.swing.JComponent.getPreferredSize(JComponent.java:1634) at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594) at java.awt.Container.layout(Container.java:1432) at java.awt.Container.doLayout(Container.java:1421) at java.awt.Container.validateTree(Container.java:1519) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validateTree(Container.java:1526) at java.awt.Container.validate(Container.java:1491) at java.awt.Window.dispatchEventImpl(Window.java:2427) at java.awt.Component.dispatchEvent(Component.java:4240) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) BUILD STOPPED (total time: 4 seconds)

My txt File:

FName Lname Number
 second secondsecond 22
 thired thithird 33
 fourth fourfourr 44
 fifth fiffif 55

Thanks for help!

View Answers

Ads









Related Tutorials/Questions & Answers:
jTable data problem
jTable data problem  Hello. I have a code that read file and store...","Number"}; List<String> data=new ArrayList<String>(); String...(){ JFrame frame=new JFrame(); JTable table=new JTable(rftl); JPanel panel
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
Advertisements
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
problem scrolling jtable
problem scrolling jtable  hi, i've to query the table thousand...;}}; table = new JTable(tableModel...); MAIN PROBLEM HERE'S M TABLE IS NOT PROPERLY SETTING IN SCROLLPANE...REPLY SOON
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
CONVERT JTable DATA TO PDF FILE
CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF... the jtable data from the jframe and stored the data into the pdf file in the form...(data, col); table = new JTable(model); JScrollPane pane = new JScrollPane(table
Display both image and data into Swing JTable
Display both image and data into Swing JTable  How To Display both image and data into Swing JTable which is retrieved from MySQL database
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane..., my problem is that this same table to see it only accepts a single line even... to rewrite my program so you can scroll and data exists in more than one line
bliffoscope data analsys problem
bliffoscope data analsys problem  Bliffoscope Data Analysis Problem... problem you have is detecting the Rejectos spaceships and slime torpedos, because... is. In other words, the data it provides is the equivalent of a black-and-white image
view data from jTextArea to jtable
view data from jTextArea to jtable  good night Please help senior java all, I want to make a brief program of reading data in the text area and then on the show to the j table. I created a new scrip like below but it does
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project... is text and all others are of currency data type. If i enter 0 or null value in currency column and then try to retrieve data using my servlet coding
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
Java convert jtable data to pdf file
Java convert jtable data to pdf file In this tutorial, you will learn how to convert jtable data to pdf file. Here is an example where we have created... have fetched the data from the jtable and save the data to pdf file. Example
Problem with appending data to the end of file
Problem with appending data to the end of file  MY JSP CODE..." import="java.io.*,data.*" %> <% String name=request.getParameter("name...: package data; import java.io.*; import java.util.*; public class musicja
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
Java swing: Export excel sheet data to JTable
Java swing: Export excel sheet data to JTable In this tutorial, you will learn how to read data from excel file and export it to JTable. In swing applications, sometimes, it is required to display the excel file data into the jtable
jtable
jtable  i have build an application and i retrieve data from... { private Vector<Vector<String>> data; //used for data from database private Vector<String> header; //used to store data header
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through... is in mysql.I want to use placeholder("?") to insert data into table.Plsssss help
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I... a employee's name from a comboBox and the jtable will be filled with all... server, and implement the needed data objects in a database server. The clients
Problem in enctype="multipart/form-data" in JSP
Problem in enctype="multipart/form-data" in JSP  im using a page... the file itself when i click the submit button. im using enctype="multipart/form-data... the uploaded value. but the problem is the uploaded file is not stored
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
JTABLE Issue
on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other... for eg. Customer's name and click to search button data comes on JTable according
here we r getting the problem with ut data and get data????????????
here we r getting the problem with ut data and get data????????????  private ArrayList keys; private ArrayList values; public Menus() { keys = new ArrayList(); values = new ArrayList(); } public
JTable Display Data From MySQL Database
JTable Display Data From MySQL Database In this section we will discuss about how to display data of a database table into javax.swing.JTable This section will describe you the displaying of data of a database table into a JTable
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans

Ads