3
I got the class Request:
package teste;
import java.util.ArrayList;
import java.util.List;
   public class Pedido {
     List<Item> lista = new ArrayList<Item>();;
     Cliente cliente;
     public Pedido adicionarPedido(int quantidade, String nome){
       lista.add(new Item(nome, quantidade));
       return this;
     }
     public Pedido paraOCliente(String nome){
        Cliente cliente = new Cliente(nome);
        return this;
     }
       public void fechar(){
           System.out.println("Nome " + this.cliente.getNome() + " " +  lista.get(0));
       }
}
The Customer class:
package teste;
   public class Cliente {
     private String nome;
     public String getNome() {
        return nome;
     }
     public void setNome(String nome) {
       this.nome = nome;
     }
     public Cliente(String nome){
       this.nome = nome;
     }
}
The class Item: test package;
   public class Item {
      private String nomeProduto;
      private int quantidade;
      public Item(String nome, int quantidade){
        this.nomeProduto = nome;
        this.quantidade = quantidade;
      }
  }
And the Main class:
package teste;
    public class Teste {
      public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Pedido().adicionarPedido(1, "tênis schutz")
                 .adicionarPedido(2, "iphone 7")
                 .paraOCliente("Aline Gonzaga")
                 .fechar(); 
    }
}
Is giving this problem:
Exception in thread "main" java.lang.NullPointerException
at teste.Pedido.fechar(Pedido.java:21)
at teste.Teste.main(Teste.java:10)
Could someone tell me what the problem is I can’t see where it is...
I see kind of bad eyes this way of using the resource, sounds like abuse of its use.
– user28595
??????????????????
– Aline
The @diegofm is absolutely right, my answer speaks of this.
– Maniero