下面是我的源代码,老是报nullpointerexception的错误,麻烦各位啦,谢谢.
package irms;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JSplitPane jSplitPane = null;
// private JTree jTree = new FunctionTree().getHashTree();
// private JScrollPane leftJScrollPane = new JScrollPane(jTree);
private JTree jTree;
private JScrollPane leftJScrollPane;
private LogoPanel logoPanel = new LogoPanel();
private String userName = "";
private String irmsDir = "D:\\PROGRESS\\IRMS\\online\\"; /**
* This is the default constructor
*/
public MainFrame(String userName) {
super();
initialize(userName);
} /**
* This method initializes this
*
* @return void
*/
private void initialize(String userName) {
this.setSize(675, 500);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Sanmina-SCI IRMS Console");
this.setVisible(true);
this.userName = userName;
this.jTree = new FunctionTree(userName).getHashTree();
this.leftJScrollPane = new JScrollPane(jTree);
this.leftJScrollPane.setBorder(BorderFactory.createTitledBorder("IRMS Menu"));
jSplitPane = this.getJContentPane();
jSplitPane.setRightComponent(logoPanel);
jSplitPane.setLeftComponent(leftJScrollPane);
this.setContentPane(jSplitPane);
doShutDownWork(); } /**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JSplitPane getJContentPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setDividerSize(5);
jSplitPane.setOneTouchExpandable(false);
jSplitPane.setEnabled(true);
}
// jSplitPane.setRightComponent(logoPanel);
// jSplitPane.setLeftComponent(leftJScrollPane);
return jSplitPane;
}
private void doShutDownWork() { Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
String fileUrl = irmsDir + userName + "login.ini";
File file = new File(fileUrl);
if(file.exists())
file.delete();
}
}); } public static void main(String[] args) {
// TODO Auto-generated method stub
MainFrame mainFrame = new MainFrame("25");
mainFrame.setVisible(true);
}}
package irms;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JSplitPane jSplitPane = null;
// private JTree jTree = new FunctionTree().getHashTree();
// private JScrollPane leftJScrollPane = new JScrollPane(jTree);
private JTree jTree;
private JScrollPane leftJScrollPane;
private LogoPanel logoPanel = new LogoPanel();
private String userName = "";
private String irmsDir = "D:\\PROGRESS\\IRMS\\online\\"; /**
* This is the default constructor
*/
public MainFrame(String userName) {
super();
initialize(userName);
} /**
* This method initializes this
*
* @return void
*/
private void initialize(String userName) {
this.setSize(675, 500);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Sanmina-SCI IRMS Console");
this.setVisible(true);
this.userName = userName;
this.jTree = new FunctionTree(userName).getHashTree();
this.leftJScrollPane = new JScrollPane(jTree);
this.leftJScrollPane.setBorder(BorderFactory.createTitledBorder("IRMS Menu"));
jSplitPane = this.getJContentPane();
jSplitPane.setRightComponent(logoPanel);
jSplitPane.setLeftComponent(leftJScrollPane);
this.setContentPane(jSplitPane);
doShutDownWork(); } /**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JSplitPane getJContentPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setDividerSize(5);
jSplitPane.setOneTouchExpandable(false);
jSplitPane.setEnabled(true);
}
// jSplitPane.setRightComponent(logoPanel);
// jSplitPane.setLeftComponent(leftJScrollPane);
return jSplitPane;
}
private void doShutDownWork() { Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
String fileUrl = irmsDir + userName + "login.ini";
File file = new File(fileUrl);
if(file.exists())
file.delete();
}
}); } public static void main(String[] args) {
// TODO Auto-generated method stub
MainFrame mainFrame = new MainFrame("25");
mainFrame.setVisible(true);
}}
package irms;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;import java.awt.Cursor;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;public class FunctionTree {
static JTree hashTree = null;
static Hashtable ht1 = new Hashtable();
static Vector menu11 = new Vector();
static Vector menu12 = new Vector();
static Vector menu13 = new Vector();
static Vector menu14 = new Vector();
static Vector menu15 = new Vector();
static Vector menu16 = new Vector();
static Runtime r = Runtime.getRuntime();
static String cmdStr = "D:\\PROGRESS\\IRMS\\online\\call_irms_program.bat 25";
static Hashtable fileNamesHash = new Hashtable(); // @jve:decl-index=0:
static Hashtable access = new Hashtable();
static Hashtable accessKeyValue = null;
static String irmsDir = "D:\\PROGRESS\\IRMS\\online\\";
static String emp_num = "25"; // @jve:decl-index=0:
static String[] accessKey = {"dep_mst",
"itm_mst",
"shf_mst",
"vnd_mst",
"cmp_mst",
"emp_mst",
"bin_mst",
"stn_mst",
"wh_mst",
"carrier_mst",
"ord_mst",
"is_backdoor",
"rpt_mst",
"sys_setup",
"param_mst",
"cust_mst",
"inv_mst",
"uom_mst",
"custom_data[2]",
"inventory_control"};
public FunctionTree(String employeeNum) {
this.emp_num = employeeNum; } public JTree getHashTree() {
menu11.addElement("Item Master");
menu11.addElement("Warehouse Zoon Setup");
menu11.addElement("Alt. Location");
menu11.addElement("Receipt Master");
menu11.addElement("Employee Master");
menu11.addElement("Work Order Tags");
menu11.addElement("Department Master");
menu11.addElement("Customer");
menu11.addElement("Inventory Detail");
menu11.addElement("Pool");
menu11.addElement("Unit Of Measure");
menu11.addElement("Carton Sizes");
menu11.addElement("Shift");
menu11.addElement("Vendor Information");
menu11.addElement("Company");
menu11.addElement("Location");
menu11.addElement("Station");
menu11.addElement("Warehouse");
fileNamesHash.put("Item Master", "itemmst.w mst");
fileNamesHash.put("Warehouse Zoon Setup", "whzone.w");
fileNamesHash.put("Alt. Location", "trk_brw.w");
fileNamesHash.put("Receipt Master", "rt_mast.w mst");
fileNamesHash.put("Employee Master", "empmst.w");
fileNamesHash.put("Work Order Tags", "wo_tag.w");
fileNamesHash.put("Department Master", "depmst.w");
fileNamesHash.put("Customer", "custmst.w");
fileNamesHash.put("Inventory Detail", "inv_brw.w");
fileNamesHash.put("Pool", "poolmst.w");
fileNamesHash.put("Unit Of Measure", "uommst.w");
fileNamesHash.put("Carton Sizes", "cartsize.w");
fileNamesHash.put("Shift", "shfmst.w");
fileNamesHash.put("Vendor Information", "venmst.w");
fileNamesHash.put("Company", "cmpmst.w");
fileNamesHash.put("Location", "LOC_BRW2.W mst");
fileNamesHash.put("Station", "stntbl.w");
fileNamesHash.put("Warehouse", "whmst.w");
menu12.addElement("Item Inquiry");
menu12.addElement("Inventory Details Inquiry");
menu12.addElement("Location Inquiry");
menu12.addElement("Order Inuqiry");
menu12.addElement("Receipt Master Inquiry");
fileNamesHash.put("Item Inquiry", "itemmst.w inq");
fileNamesHash.put("Inventory Details Inquiry", "inv_brw.w");
fileNamesHash.put("Location Inquiry", "loc_brw2.w inq");
fileNamesHash.put("Order Inuqiry", "ordhdr.w 0,inq");
fileNamesHash.put("Receipt Master Inquiry", "rt_mast.w inq");
menu13.add("Shipping");
menu13.add("Inventory Control");
menu13.add("Orders");
menu13.add("Receiving");
menu13.add("Retruns");
menu13.add("Uploading");
menu13.add("Quality Control");
menu13.add("Trailer");
fileNamesHash.put("Shipping", "shpmenu.w");
fileNamesHash.put("Inventory Control", " inv_con.w");
fileNamesHash.put("Orders", "sys-ord.w");
fileNamesHash.put("Receiving", "sys-rec.w");
fileNamesHash.put("Retruns", "retnmenu.w");
fileNamesHash.put("Uploading", "w_unload_menu.w");
fileNamesHash.put("Quality Control", "inv_qc.w");
fileNamesHash.put("Trailer", "trl_info.w");
menu14.add("Labels");
menu14.add("Reports");
menu14.add("Print Barcode");
fileNamesHash.put("Labels", "lbl_prnt.w");
fileNamesHash.put("Reports", "repmen2.w");
fileNamesHash.put("Print Barcode", "print_barcode.w mst");
menu15.add("Backup Schedule");
menu15.add("Error Message");
menu15.add("File Retention");
menu15.add("Interface");
menu15.add("Printers");
menu15.add("System Parameters");
menu15.add("System Setup");
fileNamesHash.put("Backup Schedule", "bkmst.w");
fileNamesHash.put("Error Message", "errmsg.w");
fileNamesHash.put("File Retention", "fileret.w");
fileNamesHash.put("Interface", "tr_iface.w");
fileNamesHash.put("Printers", "printers.w");
fileNamesHash.put("System Parameters", "sys-find.w");
fileNamesHash.put("System Setup", "syspara1.w"); ht1.put("Master Files", menu11);
ht1.put("Inquery Menu", menu12);
ht1.put("Modules Menu", menu13);
ht1.put("Print Menu", menu14);
ht1.put("System Setup", menu15); hashTree = new JTree(ht1);
getAccess();
hashTree.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//add select event for the JTree
hashTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
TreePath treePath = hashTree.getSelectionPath();
TreeNode treeNode = (TreeNode)treePath.getLastPathComponent();
String nodeName = treeNode.toString();
try {
if(access.get(nodeName).toString().equals("true"))
action(nodeName);
else{
String message = "Sorry, you haven't the access to " + nodeName + "!";
String dialogTitle = "Alert Information";
JOptionPane.showMessageDialog(null, message,dialogTitle,JOptionPane.ERROR_MESSAGE);;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void action(String nodeName) throws IOException{
String cmdStr = "";
FileReader fileReader = new FileReader(irmsDir + emp_num + "login.ini");
String lineStr = "";
BufferedReader bufferedReader = new BufferedReader(fileReader);
bufferedReader.readLine();
lineStr = bufferedReader.readLine();
if(lineStr.substring(lineStr.indexOf("=") + 1).equals("2")){
String message = "Sorry, you can't run two more functions at the same time!";
String dialogTitle = "Alert Information";
JOptionPane.showMessageDialog(null, message,dialogTitle,JOptionPane.ERROR_MESSAGE);;
}
else
if( fileNamesHash.get(nodeName) != null ){
cmdStr = FunctionTree.cmdStr + " "
+ fileNamesHash.get(nodeName).toString();
Thread fourGLRun = new FourGLRun(cmdStr);
fourGLRun.start();
}
}
}); return hashTree; }
String cmd = cmdStr + " access_for_java.p";
try {
Process child = Runtime.getRuntime().exec(cmd);
getProcessOutput(child);
FileReader fr = new FileReader(irmsDir + emp_num + "login.ini");
BufferedReader br = new BufferedReader(fr);
String accessStr = "";
int i = 0;
while((accessStr = br.readLine()) != null){
i ++ ;
if( i < 4)
continue;
if( accessKeyValue == null)
accessKeyValue = new Hashtable();
int startLocation = 0;
for( int j = 0; j < accessKey.length; j++ )
if( accessStr.indexOf(accessKey[j]) >= 0){
startLocation = accessStr.indexOf("=") + 1;
accessKeyValue.put(accessKey[j], accessStr.substring(startLocation));
}
}
br.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
//Alt. Location access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(12,13).equalsIgnoreCase("Y")){
access.put("Alt. Location", true);
}
else
access.put("Alt. Location", false);
//Customer access validate
if(accessKeyValue.get("cust_mst").toString().equalsIgnoreCase("yes")){
access.put("Customer", true);
}
else
access.put("Customer", false);
//Inventory Detail access validate
if(accessKeyValue.get("inv_mst").toString().equalsIgnoreCase("yes"))
access.put("Inventory Detail", true);
else
access.put("Inventory Detail", false);
//Pool access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(46,47).equalsIgnoreCase("Y"))
access.put("Pool", true);
else
access.put("Pool", false);
//Unit Of Measure access validate
if(accessKeyValue.get("uom_mst").toString().equalsIgnoreCase("yes"))
access.put("Unit Of Measure", true);
else
access.put("Unit Of Measure", false); //Work Order Tags access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(48,49).equalsIgnoreCase("Y"))
access.put("Work Order Tags", true);
else
access.put("Work Order Tags", false);
//Carton Size access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(26,27).equalsIgnoreCase("Y"))
access.put("Carton Size", true);
else
access.put("Carton Size", false);
//Department access validate
if(accessKeyValue.get("dep_mst").toString().equalsIgnoreCase("yes"))
access.put("Department Master", true);
else
access.put("Department Master", false);
//Item access validate
if(accessKeyValue.get("itm_mst").toString().equalsIgnoreCase("yes"))
access.put("Item Master", true);
else
access.put("Item Master", false);
//Shift access validate
if(accessKeyValue.get("shf_mst").toString().equalsIgnoreCase("yes"))
access.put("Shift", true);
else
access.put("Shiftl", false);
//Vendor Information access validate
if(accessKeyValue.get("vnd_mst").toString().equalsIgnoreCase("yes"))
access.put("Vendor Information", true);
else
access.put("Vendor Information", false);
//Whse Zone Setup access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(24,25).equalsIgnoreCase("Y"))
access.put("Warehouse Zoon Setup", true);
else
access.put("Warehouse Zoon Setup", false);
//Company access validate
if(accessKeyValue.get("cmp_mst").toString().equalsIgnoreCase("yes"))
access.put("Company", true);
else
access.put("Company", false);
//Employee access validate
if(accessKeyValue.get("emp_mst").toString().equalsIgnoreCase("y") || accessKeyValue.get("emp_mst").toString().equalsIgnoreCase("s"))
access.put("Employee Master", true);
else
access.put("Employee Master", false);
//Location access validate
if(accessKeyValue.get("bin_mst").toString().equalsIgnoreCase("yes"))
access.put("Location", true);
else
access.put("Location", false);
//Station access validate
if(accessKeyValue.get("stn_mst").toString().equalsIgnoreCase("yes"))
access.put("Station", true);
else
access.put("Station", false);
//Warehouse access validate
if(accessKeyValue.get("wh_mst").toString().equalsIgnoreCase("yes"))
access.put("Warehouse", true);
else
access.put("Warehouse", false);
//shipping access validate
if(accessKeyValue.get("carrier_mst").toString().equalsIgnoreCase("yes"))
access.put("Shipping", true);
else
access.put("Shipping", false);
//Orders access validate
if(accessKeyValue.get("ord_mst").toString().equalsIgnoreCase("yes"))
access.put("Orders", true);
else
access.put("Orders", false);
//Returns access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(32,33).equalsIgnoreCase("Y"))
access.put("Retruns", true);
else
access.put("Retruns", false);
//Quality Control access validate
int count = 0;
for(int i = 0; i < accessKeyValue.get("custom_data[2]").toString().length(); i++)
if(accessKeyValue.get("custom_data[2]").toString().charAt(i) == ',')
count += 1;
if(count == 25 && accessKeyValue.get("custom_data[2]").toString().substring(accessKeyValue.get("custom_data[2]").toString().lastIndexOf(',')+1).equalsIgnoreCase("y"))
access.put("Quality Control", true);
else
access.put("Quality Control", false);
//Inventory control access validate
if((accessKeyValue.get("inventory_control").toString().equalsIgnoreCase("null") && accessKeyValue.get("is_backdoor").toString().equalsIgnoreCase("yes")) || accessKeyValue.get("inventory_control").toString().equalsIgnoreCase("yes"))
access.put("Inventory Control", true);
else
access.put("Inventory Control", false);
//Unloading access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(10,11).equalsIgnoreCase("Y"))
access.put("Uploading", true);
else
access.put("Uploading", false);
if(accessKeyValue.get("custom_data[2]").toString().substring(24,25).equalsIgnoreCase("Y"))
access.put("Item Inquiry", true);
else
access.put("Item Inquiry", false);
//Inventory Detail Inquery access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(26,27).equalsIgnoreCase("Y"))
access.put("Inventory Details Inquiry", true);
else
access.put("Inventory Details Inquiry", false);
//Location Inquiry access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(28,29).equalsIgnoreCase("Y"))
access.put("Location Inquiry", true);
else
access.put("Location Inquiry", false);
//Order Inquiry access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(30,31).equalsIgnoreCase("Y"))
access.put("Order Inuqiry", true);
else
access.put("Order Inuqiry", false);
//Receipt Master Inquiry access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(32,33).equalsIgnoreCase("Y"))
access.put("Receipt Master Inquiry", true);
else
access.put("Receipt Master Inquiry", false);
//Labels access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(18,19).equalsIgnoreCase("Y"))
access.put("Labels", true);
else
access.put("Labels", false);
//Reports access validate
if(accessKeyValue.get("rpt_mst").toString().equalsIgnoreCase("yes"))
access.put("Reports", true);
else
access.put("Reports", false);
//Backup Schedule access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(34,35).equalsIgnoreCase("Y"))
access.put("Backup Schedule", true);
else
access.put("Backup Schedule", false);
//Interfaces access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(36,37).equalsIgnoreCase("Y"))
access.put("Interface", true);
else
access.put("Interface", false);
//Error Message access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(38,39).equalsIgnoreCase("Y"))
access.put("Error Message", true);
else
access.put("Error Message", false);
//Printers access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(40,41).equalsIgnoreCase("Y"))
access.put("Printers", true);
else
access.put("Printers", false); //File Retention access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(42,43).equalsIgnoreCase("Y"))
access.put("File Retention", true);
else
access.put("File Retention", false);
//System Parameters access validate
if(accessKeyValue.get("custom_data[2]").toString().substring(38,40).equalsIgnoreCase("V") || accessKeyValue.get("param_mst").toString().equalsIgnoreCase("yes") )
access.put("System Parameters", true);
else
access.put("System Parameters", false);
//System Setup access validate
System.out.println(accessKeyValue.get("sys_setup").toString());
if(accessKeyValue.get("sys_setup").toString().equalsIgnoreCase("yes"))
access.put("System Setup", true);
else
access.put("System Setup", false);
}
public static void getProcessOutput(Process p){
InputStream in = p.getInputStream();
int c;
try {
while ((c = in.read()) != -1) {
}
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}