6 Replies - 1390 Views - Last Post: 08 December 2010 - 08:56 AM Rate Topic: -----

#1 kuaq11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 10

Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 09:02 PM

This is the code......
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.Dialog.*;
import javax.swing.JOptionPane.*;

class Enquiry implements Comparable {
private int number;
private int time;
private String name;
private String branch;
private String enquiry;
public Enquiry(int m, int t, String n, String b, String q) {
number = m;
name = n;
branch = b;
time = t;
enquiry = q;
}

public Enquiry() {
this(0, 0, "", "", "");
}


public int getNumber() {
return number;
}

public int getTime() {
return time;
}

public String getName() {
return name;
}
public String getBranch() {
return branch;
}
public String getEnquiry() {
return enquiry;
}

public int compareTo(Object o) {
Enquiry temp = (Enquiry) o;

return (name.compareTo(temp.name));

}
}
public class GUI2 extends JFrame {

ArrayList enquiries = new ArrayList();

JPanel panInput = new JPanel(new GridLayout(4,1)),
panAdd = new JPanel(),
panDelSort = new JPanel();

JTextField txtName = new JTextField(10);
JTextField txtBranch = new JTextField(10);
JTextField txtEnquiry = new JTextField(10);
JTextField txtNumber = new JTextField(10);
JTextField txtTime = new JTextField(5);
JButton btnAdd = new JButton("Add"),
btnDelete = new JButton("Delete"),
btnSort = new JButton("Sort by Name");
JButton btnSortTime = new JButton("Sort by plus time");

JTable tab = new JTable();

DefaultTableModel tabMod = new DefaultTableModel();


public GUI2() {
super("Product list");
tab.setModel(tabMod);
tabMod.addColumn("Name");
tabMod.addColumn("Telephone number");
tabMod.addColumn("Branch");
tabMod.addColumn("Callback time");
tabMod.addColumn("Enquiry");
tab.setAutoCreateRowSorter(true);
loadInitialEnquiries();


btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

addEnquiry();

if (txtNumber.getText() != null) {
JOptionPane.showMessageDialog(null, "Please input a correct phone number and/or a time form");
}
else addEnquiry();



}

});

btnDelete.setToolTipText("Select the record(s) to delete first");
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
deleteEnquiry();
}
});
btnSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
sortEnquiriesName();
}
});

btnSortTime.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
sortEnquiriesTimeAsc();
}
});

panAdd.add(btnAdd);
panAdd.add(new JLabel("Name"));
panAdd.add(txtName);
panAdd.add(new JLabel("Telehpone number"));
panAdd.add(txtNumber);
panAdd.add(new JLabel("Branch"));
panAdd.add(txtBranch);
panAdd.add(new JLabel("Callback Time"));
panAdd.add(txtTime);
panAdd.add(new JLabel("Enquiry"));
panAdd.add(txtEnquiry);
panDelSort.add(btnDelete);
panDelSort.add(btnSort);
panDelSort.add(btnSortTime);
panInput.add(panAdd);
panInput.add(panDelSort);
getContentPane().add(panInput, BorderLayout.SOUTH);
getContentPane().add(new JScrollPane(tab));

}
public void deleteEnquiry() {

int [] rows = tab.getSelectedRows();
for (int i = 0; i < rows.length; i++) {
tabMod.removeRow(rows[i] - i);
enquiries.remove(rows[i] - i);

}

}

public void sortEnquiriesName() {
Collections.sort(enquiries);
loadProductsIntoTable();
}

public void sortEnquiriesTimeAsc() {
Collections.sort(enquiries);
loadProductsIntoTable();
}

public void addEnquiry() {
String [] row = new String [5];
Enquiry newEnq = new Enquiry
(Integer.parseInt(txtNumber.getText()), (Integer.parseInt(txtTime.getText())),
txtName.getText(),
txtBranch.getText(), txtEnquiry.getText()
);

enquiries.add(newEnq);
row[0] = newEnq.getName();
row[1] = Integer.toString(newEnq.getNumber());
row[2] = newEnq.getBranch();
row[3] = Integer.toString(newEnq.getTime());
row[4] = newEnq.getEnquiry();
tabMod.addRow(row);


}
public void loadInitialEnquiries() {
BufferedReader br = null;
try {
br = new BufferedReader(
new FileReader("Log.txt"));

String s;
int colCount = tab.getColumnCount();
String[] row = new String[colCount];

while ((s = br.readLine()) != null) {
if(s.equals("<stock_enquiry>")) {
row[0] = br.readLine(); // name
row[1] = br.readLine(); // phone
row[2] = br.readLine(); // branch
row[3] = br.readLine(); // time
row[4] = br.readLine(); // enquiry
tabMod.addRow(row);
}

}

br.close();
}
catch(IOException e) {
System.out.println("loadInitialEnquiries i/o error: " +
e.getMessage());
}

}
public void loadProductsIntoTable() {
tabMod.setRowCount(0);

String [] row = new String [5];
for (Iterator i = enquiries.iterator(); i.hasNext() ; ) {
Enquiry temp = (Enquiry) i.next();
row[0] = temp.getName();
row[1] = Integer.toString(temp.getNumber());
row[2] = temp.getBranch();
row[3] = Integer.toString(temp.getTime());
row[4] = temp.getEnquiry();
tabMod.addRow(row);
}
}
private JScrollPane getContent() {
return new JScrollPane(tab);
}

public static void main(String [] a){
GUI2 me = new GUI2();
JFrame j = new JFrame();
j.add(me.getContent());

me.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0) ;
}
});
me.pack();
me.setVisible(true);
}
}


Log text file
------------------------------------------------
<stock_enquiry>
Pink, Polly
020 8567 1234
PC Planet, Greenwich
13:45
I'd like help finding the number of printers we have got.
</stock_enquiry>
<stock_enquiry>
Red, Ryan
020 7465 9984
Digital Outlet, Gatwick
12:50
What is the top of the range digital camera we stock?
</stock_enquiry>

----------------------------------------
error in netbean loadInitialEnquiries i/o error: Log.txt (The system cannot find the file specified)

try many time to fix this error but failed but when I am run in jcreator platform there is no error come out but no data from log.txt load in jtable.

Attached Image

This post has been edited by macosxnerd101: 07 December 2010 - 09:16 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 09:25 PM

And what this the error message ?
With the line number
and if it is at line 185 it is because the file is not there

and indent your code properly.... how can you expect us to read code like

try {
br = new BufferedReader(
new FileReader("Log.txt"));

A compiler can, you are exhausting me
Was This Post Helpful? 0
  • +
  • -

#3 kuaq11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 10

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 09:38 PM

View Postpbl, on 07 December 2010 - 08:25 PM, said:

And what this the error message ?
With the line number
and if it is at line 185 it is because the file is not there

and indent your code properly.... how can you expect us to read code like

try {
br = new BufferedReader(
new FileReader("Log.txt"));

A compiler can, you are exhausting me


I`am Sorry

This is my first java code. I`am using netbean platform, when I run the project its only come out with the interface but there no data load from log.txt and it show this message - loadInitialEnquiries i/o error: Log.txt (The system cannot find the file specified)
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 09:47 PM

View Postkuaq11, on 07 December 2010 - 10:38 PM, said:

I`am Sorry

No problem

Quote

This is my first java code. I`am using netbean platform, when I run the project its only come out with the interface but there no data load from log.txt and it show this message - loadInitialEnquiries i/o error: Log.txt (The system cannot find the file specified)

So the file is not there... I seriously doubt there is a problem with the constructor of FileReader() in Java run time library. This constructor must be called a few thousand times every second over the planet without problem.

Post an output of your directory in Windows or ls on Unix where both your Enquiry.class and Log.txt should be
Was This Post Helpful? 0
  • +
  • -

#5 kuaq11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 10

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 10:08 PM

Quote

So the file is not there... I seriously doubt there is a problem with the constructor of FileReader() in Java run time library. This constructor must be called a few thousand times every second over the planet without problem.

Post an output of your directory in Windows or ls on Unix where both your Enquiry.class and Log.txt should be


I already put the enquiry.class and log.txt into one folder but still come out with an error. and I also rename that log.txt file with another name but still failed.

Attached Image

This post has been edited by kuaq11: 07 December 2010 - 10:08 PM

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 07 December 2010 - 10:29 PM

asked you about a DIR or ls output of where your .class and .txt file are

and the stack output error
Was This Post Helpful? 0
  • +
  • -

#7 kuaq11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 10

Re: Error loadInitialEnquiries i/o error: Log.txt (The system cannot find

Posted 08 December 2010 - 08:56 AM

View Postpbl, on 07 December 2010 - 09:29 PM, said:

asked you about a DIR or ls output of where your .class and .txt file are

and the stack output error


I already fix the directory error, by put the right directory "C:/Documents and Settings/User/My Documents/NetBeansProjects/Project/Project/src/Log.txt" but when compile or run the GUI2 the data from text file still cannot load to jtable..but there is no error show...you can refer it in the attachment picture of my Netbean screen shot

  }
    BufferedReader br = null;
        try {
                br = new BufferedReader(
                 new FileReader("C:/Documents and Settings/User/My Documents/NetBeansProjects/Project/Project/src/Log.txt"));





Attached Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1