2012-07-05 25 views
-1

我正在使用提供用户界面来执行某些用户事件的Java项目。它不像在大多数Swing/Gui应用程序中那样作为main()中的Runnable线程执行。相反,它在源代码中有几个类和表单文件,并使用另一个Java程序从命令行运行。 但是当我试图通过单击某个输入按钮来读取某个文件时,系统无法读取该文件。系统将自定义错误消息写入保存在项目文件夹中的名为log.txt的文件中。 我试图 1.设置断点(应用程序没有在断点处停止) 2.做控制台打印即的System.out.println(有控制台上没有打印)在Java GUI应用程序中调试用户事件

因此,无论调试的方法已经失败。我正在使用Eclipse 3.5.2 SDK(伽利略)。我如何在应用程序上调试用户事件?

下面列出了项目DDMT中源类DataImportPanel的轮廓。它在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 

这里是一个被扔在数据导入例外

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()+"!"); 
    } 
} 
+0

你在“调试”模式下运行吗?如果不是,则不会触发断点。 – user1329572 2012-07-05 12:51:44

+0

是的我已经运行在调试模式下(调试透视图) – somnathchakrabarti 2012-07-05 12:57:10

+0

如果您从命令行运行它,您是否将其设置为调试并连接到“远程Java应用程序”? – 2012-07-05 13:14:20

回答

1

有一点点绿色瓢虫旁边的启动调试运行按钮的openHeteroFile。

我会确保正确的呼叫正在进行。同时检查括号,中断和返回以确保代码实际上正在被读取。请发布SSCCE(简短,自包含,正确的示例),以便我们可以查看您的代码以更好地帮助您。

编辑(OP后添加一些代码)

我敢肯定你的问题是,你file.createNewFile();

+0

我已经添加了完整项目解决方案的代码大纲。 – somnathchakrabarti 2012-07-05 13:38:27

+0

要指定一个SSCCE,我会说我有两个java文件 - Launcher.java和DataImportPanel.java。我使用启动用户界面的“java -cp * .jar DDMT.core.Launcher true”从shell提示符调用Launcher类。 DataImportPanel处理此界面中的一个面板。 DataImportPanel的openHeteroFile(File)方法无法读取选定的文件。我想从DataImportPanel调试用户事件驱动的代码。但在调试模式下设置正常断点或者甚至给出值打印输出(System.out.println)不起作用。 – somnathchakrabarti 2012-07-05 13:46:05

+0

这仍然没有给我们一个SSCCE。我们需要能够查看您的代码,以便充分了解问题出在哪里 – 2012-07-05 13:49:57