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
Related Tutorials/Questions & Answers:
jTable data problemjTable 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
Advertisements
problem with JTable - Swing AWTproblem 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
problem Scrolling jTable in scrollpaneproblem 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 scrollpaneproblem 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 jtableproblem scrolling jtable hi,
i've to query the table thousand... = new
JTable(tableModel...);
pane.setSize(600,300);
pane.setVisible(true);
MAIN
PROBLEM CONVERT JTable DATA TO PDF FILECONVERT
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
jtablejtable 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
display dinamic data in JTable - Swing AWTdisplay 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 jtableview
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
JTableJTable Hello, i cannot display
data from my table in the database to the cells of my
JTable. please help me
Java insert file data to JTableJava 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... and
store the
data into vector. Then pass the vector value as a parameter to
the
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
Extract File data into JTableExtract 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
bliffoscope data analsys problembliffoscope
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
Java convert jtable data to pdf fileJava 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 in inserting clob data in jspProblem in inserting clob
data in jsp how to insert any rich text editor
data (which have more than 32766 characters) in a clob type column of oracle database with jsp
JTableJTable Values to be displayed in JTextfield when Clicked on
JTable Cells
JTableJTable 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
Problem in accessing data from DatabaseProblem 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
JTableJTable 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
JTableJTable need to add values to a
JTable having 4 coloumns ,2 of them are comboboxes
Problem with appending data to the end of fileProblem 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
jtablejtable 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
jtablejtable 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 JTableJava 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 jtablejtable 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
Problem in enctype="multipart/form-data" in JSPProblem 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-JavaJtable-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
a little problem in read data - Java Beginnersa little
problem in read data ok Vinod Kumar and friend, i already use this code. but is
data null, this code will error5 again. How the
data can go to database with null
data. ex: value = (d00001;Operation;Finance;Finance Head
JTable Display Data From MySQL DatabaseJTable 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 queryjtable 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 JtableABOUT 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
JTable - Java BeginnersJTable 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
regarding JTable - JDBCregarding JTable how to populate a
JTable with mysql
data after clicking JButton
please explain with the example
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
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