Home Answers Viewqa Java-Beginners jTable data problem

 
 


A Polite Boy
jTable data problem
0 Answer(s)      5 months and 13 days ago
Posted in : Java Beginners

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









Related Pages:
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
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
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
problem with JTable - Swing AWT
problem with JTable  hi guys, i was a student and i am very new to swings.i was having an assignment like i need to create a JTable... an action event such that if i check the checkbox outside the JTable,all the checkboxes
jtable problem
jtable problem  how to make a cell text hypertext
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
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  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 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 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
Connecting JTable to database - JDBC
"}; DefaultTableModel model = new DefaultTableModel(data, col); table = new JTable...Connecting JTable to database  Hi.. I am doing a project on Project... interface in which i have used JTables.. Now my problem is I dont know how to how
JTable - Java Beginners
JTable  Hi, I have some problem with JTable. On show All button hit.... my problem is with Jtable, sometimes it is visible and sometimes it is not. when...(); JTable table = new JTable(data, columnNames); sp=new JScrollPane(table
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 - Java Beginners
); } res2.close(); stat3.close(); JTable table = new JTable(data... table = new JTable(data, columnNames); TableColumn col... want my JTable on the panel. and i also want to increase height and width
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
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
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
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane...REPORT WITH JTABLE  i have data in backend(oracle10g,spl+).i want the data into front end(java jdk) with the help of jtables thnx in advance  
JTable - JDBC
DefaultTableModel(data,col); tb=new JTable(model); sp=new JScrollPane(tb...JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's
display dinamic data in JTable - Swing AWT
display dinamic data in JTable  Hi, I need some help to development... and to read data in each files of this directory and to display it in one JTable... in this directory now i want to display the data of each files
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
adding data to the database with the use of jtable - Java Beginners
adding data to the database with the use of jtable  how can i add data to the database with the use of jtable. and also can able to view the records in the database in the table.. tnx :G
adding data to the database with the use of jtable - Java Beginners
adding data to the database with the use of jtable  how can i add data to the database with the use of jtable. and also can able to view the records in the database in the table.. tnx :G
Java insert file data to JTable
Java insert file data to JTable In this section, you will learn how to insert text file data into JTable. Swing has provide useful and sophisticated set...); } }  Through the above code, you can insert the file data into JTable
JTable - Java Beginners
JTable search example  I've problem about JTable, i wan to search records when i types words in JTable cell,can u give the source code.I'm Beginner and i start begins learning java programming.Please send the example into my
Extract File data into JTable
Extract File data into JTable In this section, you will learn how to read the data from the text file and insert it into JTable. For this, we have created... the BufferedReader class, we have read the data of the file. This data is then broken
printout problem
) ); } data.addElement( row ); } } catch(Exception e){} JTable table = new JTable(data... some data and fetch some data from DB . Now I want a print feature by which i want to take a print out of that data in form of table. What should I do to achieve
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
jtable query compare with date
jtable query compare with date  how to transfer daytable data to monthtable when complete a month
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset... is helpful in displaying data in tabular format. You can also edit data. JTable... not contain data. You can define your table as ? JTable table=new JTable(data
jtable query compare with date
jtable query compare with date  how to transfer daytable data... in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code
jtable query compare with date
jtable query compare with date  how to transfer daytable data... in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code
jtable query compare with date
jtable query compare with date  how to transfer daytable data... in which i have to display database records in jtable .now I want to transfer particular data which month is over to another jtable. plz sir give me the code
JTable - Swing AWT
JTable  Hi Deepak, i want to display the Jtable data... how could i show jtable data on the console. Thanks, Prashant   Hi...*; public class JTableToConsole extends JFrame { public Object GetData(JTable
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
JTable - Swing AWT
JTable  Hi Deepak, i m facing a problem with jtable. i am able to display the values from the database into the jtable. but not able to modifying multiple cell values in a row. also i want to store those modified
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running... and if the user want enter the data to a 4th row he must press enter at the end of the 3rd
java swing (jtable)
){ System.out.println(e); } JTable table = new JTable(data, columnNames); TableColumn col; for (int...java swing (jtable)  hii..how to get values of a particular record in jtable from ms access database using java swing in netbeans..?? please help
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
Jtable Question - Java Beginners
Jtable Question  Hello Sir, I have Created Database in MS access 2007 ,I want show the table data in to Swing JTable, How I can Show it, plz Help... JTable(data, columnNames); TableColumn col; for (int i = 0; i <
jtable combo - Java Beginners
jtable combo  i am using jtable (using defaulttablemodel) ,when i am click on a particular cell of jtable i want to display the combo box...()); String data[][] = {{"",""},{"",""},{"",""},{"",""}}; String col
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
update a JTable - Java Beginners
update a JTable   how to update a JTable with Mysql data through user... in an updatable JTable You would create the table as follows: conn... = new ResultSetTableModel(rs); table = new JTable(model
update a JTable - Java Beginners
update a JTable   i have tried your advice as how to update a JTable with mysql data through user interface but it is resulting some errors here...*; import java.awt.event.*; public class data extends JFrame {public static void
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
search filter and JTable
my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont...","Contact No","Email"}; JTable table=new JTable(data,labels