enter code here
私はプライベートブール値を持っていますexist=false;
。これは私のローカル変数ですpayrool class
方法もありますsearchRecord(int payrollPeriod, int empNo)
public void searchRecord(int payrollPeriod, int empNo)
{
for(int x=0;x<100;x++)
{
if(trans[x].getPayrollPeriod() == payrollPeriod && trans[x].getEmpNo() == empNo)
{
payrollCounter=x;
exist=true;
break;
}
}
}
私の配列trans[]
は、とTransaction
を持つレコードで構成されるタイプです (私はコンポジションを使用しました) 。payrollPeriod
empNo
ファイルが存在するときはいつでも私のプログラムは正常に実行されますが、検索結果が false にjava.lang.NullPointerException
なると...
助けてください、どうすればいいですか
エラー:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at payroll.Payroll.searchRecord(Payroll.java:350)
at payroll.Payroll.actionPerformed(Payroll.java:184)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
取引クラス:
package payroll;
public class Transaction extends Employee
{
//local variable
private int payrollPeriod;
private double hoursWorked;
//constructor
public Transaction(int payrollPeriod, int empNo, String name, String department, double payRate, double hoursWorked)
{
super(empNo, name, department, payRate);
this.payrollPeriod=payrollPeriod;
this.hoursWorked=hoursWorked;
}
//methods
public int getPayrollPeriod()
{
return payrollPeriod;
}
public double getHoursWorked()
{
return hoursWorked;
}
}