0

首先,对不起英语不好-

我想从“Ventas”移动到“Historico”,只有与“Clientes”中的“codCli”具有相同代码的对象,这是我的代码:

public static void Eliminar_Cliente(){

        System.out.println("Que cliente quieres eliminar? (Introduce el código de cliente)");
        int cliE=(sc.nextInt()-1);

        Cliente clienteBuscado=null;

        for (Cliente cliente : cli) {
            if(cliente.codCli==cliE) clienteBuscado=cliente;
        }

        if(clienteBuscado!=null)
        {
          ArrayList<Ventas> ventaAux=new ArrayList();

          for (Ventas venta : vent) {   
              System.out.println("asddsa");
              if (venta.cliente==clienteBuscado.codCli){
                  Historico h = new Historico(venta);
                  his.add(h);
                  ventaAux.add(venta);
              }
          }

          if(!ventaAux.isEmpty())
          {
              for (Ventas ventas : ventaAux) {
                  vent.remove(ventas);
              }
          }

        }

    }

但输出绝对没有,它甚至没有进入每个循环的 Ventas'。

有什么帮助吗?

4

1 回答 1

2

More than likely, the Collection vent is empty. Ensure that the Collection is populated correctly prior to invoking Eliminar_Cliente.

Also if clienteBuscado is null the if statement block where the for loop is invoked will never be entered -> ensure that clienteBuscado is assigned a value.

And more fundamentally make sure you're actually invoking Eliminar_Cliente.

Aside: Java naming conventions use camelCase for method names, for example eliminarCliente

于 2013-06-06T13:36:28.377 回答