From 694a84666043b36c1d59857bdabbe5bec81b230a Mon Sep 17 00:00:00 2001 From: Alex Wang Date: Sun, 20 Jan 2013 10:28:48 -0800 Subject: [PATCH] Fix null pointer exception when no component is selected --- .../src/versionchecker/actions/VCArtifactTable.java | 8 ++++++-- .../src/versionchecker/actions/VCMainWindow.java | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/VersionChecker/src/versionchecker/actions/VCArtifactTable.java b/VersionChecker/src/versionchecker/actions/VCArtifactTable.java index ad3ae73..a7b0782 100644 --- a/VersionChecker/src/versionchecker/actions/VCArtifactTable.java +++ b/VersionChecker/src/versionchecker/actions/VCArtifactTable.java @@ -84,11 +84,15 @@ public void mouseClicked(MouseEvent e) { } public String getSelectedID() { - return this.selectedAF.getId(); + if (this.selectedAF != null) + return this.selectedAF.getId(); + return null; } public String getSelectedVer() { - return this.selectedAF.getVersion(); + if (this.selectedAF != null) + return this.selectedAF.getVersion(); + return null; } private void addEntry(VCArtifact toAdd) { diff --git a/VersionChecker/src/versionchecker/actions/VCMainWindow.java b/VersionChecker/src/versionchecker/actions/VCMainWindow.java index d660cd9..cce5bdc 100644 --- a/VersionChecker/src/versionchecker/actions/VCMainWindow.java +++ b/VersionChecker/src/versionchecker/actions/VCMainWindow.java @@ -11,6 +11,7 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; @@ -120,7 +121,10 @@ public void actionPerformed(ActionEvent event) { fetchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String id = tablePanel.getSelectedID(); - VCCloneTask task = new VCCloneTask(id,null); + if (id != null) + new VCCloneTask(id,null); + else + JOptionPane.showMessageDialog(null, "No component is selected.", "VersionChecker", 1);; } }); @@ -128,7 +132,10 @@ public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) { String id = tablePanel.getSelectedID(); String ver = tablePanel.getSelectedVer(); - VCCloneTask task = new VCCloneTask(id,ver); + if (id != null) + new VCCloneTask(id,ver); + else + JOptionPane.showMessageDialog(null, "No component is selected.", "VersionChecker", 1);; } });