これは、プログラムを実行しようとしたときに発生するエラーです。正直なところ、コードをどこから開始すればよいか本当にわかりません。私は新旧のボタン名を持っています。textfieldMemberID に yearToday と、組織に参加したメンバーの配列を表示する必要があります。たとえば、新規をクリックすると、textfieldMemberId の値は自動的に「2012-000001」と表示され、もう一度新規をクリックすると「2012-000002」と表示されます。' 私はメンバー クラスを持っています:
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class Member {
private ArrayList accounts;
private String MemberId;
private String VotersId;
private String FirstName;
private String MiddleName;
private String LastName;
private String LotNo;
private String Street;
private String Barangay;
private String City;
private String Region;
private int Age;
private String Gender;
private Date Birthday;
private String ContactNo;
private String EmailAddress;
private int size=0;
private int yearToday = Calendar.getInstance().get(Calendar.YEAR);
public Member(String MemberId) {
NumberFormat formatter = new DecimalFormat("000000");
size= this.accounts.size()+1;
this.setMemberId(""+yearToday + "-" + (formatter.format(size)));
} //im trying to have the solution here
public Member(String MemberId,String FirstName,String MiddleName,String LastName){
this.setMemberId(MemberId);
this.setFirstName(FirstName);
this.setMiddleName(MiddleName);
this.setLastName(LastName);
}
public int getAge() {
return Age;
}
public void setAge(int Age) {
this.Age = Age;
}
public String getBarangay() {
return Barangay;
}
public void setBarangay(String Barangay) {
this.Barangay = Barangay;
}
public Date getBirthday() {
return Birthday;
}
public void setBirthday(Date Birthday) {
this.Birthday = Birthday;
}
public String getCity() {
return City;
}
public void setCity(String City) {
this.City = City;
}
public String getContactNo() {
return ContactNo;
}
public void setContactNo(String ContactNo) {
this.ContactNo = ContactNo;
}
public String getEmailAddress() {
return EmailAddress;
}
public void setEmailAddress(String EmailAddress) {
this.EmailAddress = EmailAddress;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String FirstName) {
this.FirstName = FirstName;
}
public String getGender() {
return Gender;
}
public void setGender(String Gender) {
this.Gender = Gender;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
this.LastName = LastName;
}
public String getLotNo() {
return LotNo;
}
public void setLotNo(String LotNo) {
this.LotNo = LotNo;
}
public String getMemberId() {
return MemberId;
}
public void setMemberId(String MemberId) {
this.MemberId = MemberId;
}
public String getMiddleName() {
return MiddleName;
}
public void setMiddleName(String MiddleName) {
this.MiddleName = MiddleName;
}
public String getRegion() {
return Region;
}
public void setRegion(String Region) {
this.Region = Region;
}
public String getStreet() {
return Street;
}
public void setStreet(String Street) {
this.Street = Street;
}
public String getVotersId() {
return VotersId;
}
public void setVotersId(String VotersId) {
this.VotersId = VotersId;
}
public ArrayList getAccounts() {
return accounts;
}
public void setAccounts(ArrayList accounts) {
this.accounts = accounts;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Member other = (Member) obj;
if ((this.MemberId == null) ? (other.MemberId != null) : !this.MemberId.equals(other.MemberId)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 89 * hash + (this.MemberId != null ? this.MemberId.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "Member{" + "MemberId=" + MemberId + ", VotersId=" + VotersId + ", FirstName=" + FirstName + ", MiddleName=" + MiddleName + ", LastName=" + LastName + ", LotNo=" + LotNo + ", Street=" + Street + ", Barangay=" + Barangay + ", City=" + City + ", Region=" + Region + ", Age=" + Age + ", Gender=" + Gender + ", Birthday=" + Birthday + ", ContactNo=" + ContactNo + ", EmailAddress=" + EmailAddress + '}';
}
}
ボタン「新規」のこのコードでgetmemberIdを呼び出そうとしています
String last="";
last = member.getMemberId();
this.txtMembersID.setText((last));
しかし、私はこのエラーが発生しました。 スレッド「AWT-EventQueue-0」での例外 java.lang.NullPointerException 助けてください。ありがとう。