I am using a Java Project that gives an user interface for doing some user events. It is not being executed as Runnable thread in main() as in most Swing/Gui applications. Rather it has several class and form files in the source code and is run from command line using another Java program.
But when I am trying to read a certain file by clicking on some input button, the system fails to read the file. The system writes the custom error message into a file named log.txt saved within the project folder.
I have tried
1. Setting breakpoints (the application does not stop at breakpoint)
2. Doing console prints i.e. System.out.println (there is no print on console)
So both the ways of debugging has failed. I am using Eclipse 3.5.2 SDK (Galileo). How can I debug the user events on my applicattion?
The outline of the source class DataImportPanel in project DDMT is listed below. It is giving an exception in the method DataImportPanel.openHeteroFile(File).
DDMT.core.DataImportPanel
...
DDMT.core.DataImportPanel.heteroDistributionModel
...
DDMT.core.DataImportPanel.initComponents()
DDMT.core.DataImportPanel.initComponents().new ActionListener() {...}
...
DDMT.core.DataImportPanel.initComponents().new MouseAdapter() {...}
DDMT.core.DataImportPanel.initComponents().new ActionListener() {...}
DDMT.core.DataImportPanel.jButton2ActionPerformed(ActionEvent)
...
DDMT.core.DataImportPanel.jButton3ActionPerformed(ActionEvent)
DDMT.core.DataImportPanel.openHeteroFile(File)
DDMT.core.DataImportPanel.jButton8ActionPerformed(ActionEvent)
DDMT.core.DataImportPanel.openFile(File)
DDMT.core.DataImportPanel.jButton15ActionPerformed(ActionEvent)
DDMT.core.DataImportPanel.jRadioButton1ActionPerformed(ActionEvent)
DDMT.core.DataImportPanel.buttonGroup1
...
DDMT.core.DataImportPanel.jButton8
DDMT.core.DataImportPanel.jButton9
DDMT.core.DataImportPanel.jLabel1
...
DDMT.core.DataImportPanel.jList1
...
DDMT.core.DataImportPanel.jPanel1
...
DDMT.core.DataImportPanel.jRadioButton1
...
DDMT.core.DataImportPanel.jScrollPane1
...
DDMT.core.DataImportPanel.jTabbedPane1
DDMT.core.DataImportPanel.DistributionTypes
DDMT.core.DataImportPanel.DoubleCellRenderer
Here is the openHeteroFile which is throwing the Data Import exception
private void openHeteroFile(File f)
{
File file = null;
try{
file = f;
file.createNewFile();
FileReader reader = new FileReader(file);
BufferedReader bReader = new BufferedReader(reader);
//The vector that holds the number of columns
attributeNames = new ArrayList<String>();
//Read in the number of pairs
String line = bReader.readLine();
//load the file
heteroDistributionModel = new DefaultListModel();
line = bReader.readLine();
while( line != null )
{
//Set up the RegEx matches
heteroDistM = heteroDistP.matcher(line);
firstM = firstP.matcher(line);
firstM.find();
String output1 = firstM.group()+" (";
for( int j = 0; j< nodeTypes[0].length; j++)
{
if( controlClass.nodes[Integer.parseInt(firstM.group())].getNodeType().equals( nodeTypes[1][j]) )
{
output1 = output1+nodeTypes[0][j]+")";
}
}
String output2 = new String();
while( heteroDistM.find() )
{
attributeNames.add(heteroDistM.group(1));
output2 = output2 + " "+heteroDistM.group(1);
}
heteroDistributionModel.addElement(new String[]{output1, output2});
line = bReader.readLine();
}
for (String attr : attributeNames)
System.out.println(attr); //debug
jList3.setModel(heteroDistributionModel);
jList3.setCellRenderer(new DoubleCellRenderer());
bReader.close();
reader.close();
}catch(IOException ex)
{
controlClass.showError("Data Import: Error: File "+file.getPath()+" is not a valid Heterogeneous data file!");
}catch(Exception ex)
{
ex.printStackTrace(); //debug
controlClass.showError("Data Import: Error: Unknown problem reading file "+file.getPath()+"!");
}
}
There is a little green ladybug right next to the run button that starts the debugger.
I would make sure the proper calls are being made. Also check your brackets, breaks, and returns to make sure the code is actually being read. Please post a SSCCE (Short, Self Contained, Correct Example) so we can view your code to help you out better.
Edit (after OP added some code)
I’m pretty sure your issue is where you file.createNewFile();