0
I have a project for the college, a simple schedule, no graphic parts or database.
There are four classes: Contact, Commitment, Schedule and Test. In the Contact and Commitment classes we have only the basic variables and their constructors, getters and setters.In the Agenda class we have the methods to insert contact, insert commitment, delete contact, delete appointment, list contact and list appointment and the Test class is the main class.
The whole contact part works, but the insert commitment methods returns me "Exception in thread "main" java.lang.Nullpointerexception"
Code of the Commitment Class.
public class Compromisso {
private String data;
private String descricao;
public Compromisso(String data, String descricao) {
this.data = data;
this.descricao = descricao;
}
public Compromisso() {
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
Code of Methods Insert Contact and Insert Commitment:
private int qtdMaxContato = 100;
private int qtdContato;
private int qtdMaxCompromisso = 100;
private int qtdCompromisso;
private Contato[] Contato;
private Compromisso[] Compromisso;
public Agenda() {
this.Contato = new Contato[100];
this.Compromisso = new Compromisso[100];
}
// Getters e Setters e outros métodos.
public void InserirContato(String nome, String telefone, String celular, String email, String nascimento) {
Contato novo = new Contato(nome, telefone, celular, email, nascimento);
Contato[qtdContato] = novo;
qtdContato++;
}
public void InserirCompromisso(String data, String descricao) {
this.Compromisso[qtdCompromisso].setData(data);
this.Compromisso[qtdCompromisso].setDescricao(descricao);
qtdCompromisso++;
}
Code class Test:
public static void main(String[] args) {
Agenda a1 = new Agenda();
a1.InserirCompromisso("22/22/22", "testetestetestetestetesteteste");
a1.ListarCompromisso();
}
Does this mistake only happen on my computer? how do I fix it?
Which line crashes the error? You can post the stack trace?
– Jéf Bueno