I do not increase the% with the Method ups Salary I get java.lang.NullPointerException [duplicated]

0
  

I get the error java.lang.NullPointerException, but I do not understand why, when I put the static method I did not get the error but I did not increase the% equally, I do not understand what the error is if it is the initialization or something else and "I mean the Method ups Salary class class"

 public static void main(String arg[]) {

        Empleado [] misEmpleados = new Empleado[3];

        String nombre;
        String sueldo = null;
        String año,mes,dia;
        String Empleado ;
        String porcentaje;



    for (Empleado e:misEmpleados ) {

        Empleado = JOptionPane.showInputDialog("Empleado o Jefe : \n Jefe : J \n Empleado : E");
        nombre = JOptionPane.showInputDialog("Ingrese el nombre del empleado  : ");
        sueldo = JOptionPane.showInputDialog("Ingrese el Sueldo : ");
        año = JOptionPane.showInputDialog("El año");
        mes = JOptionPane.showInputDialog("El mes");
        dia = JOptionPane.showInputDialog("El dia");
        porcentaje = JOptionPane.showInputDialog("Ingrese el % del sueldo que desea Incrimentar : ");

        double sueld = Double.parseDouble(sueldo);
        int añoInt= Integer.parseInt(año);
        int mesInt = Integer.parseInt(mes);
        int diaInt = Integer.parseInt(dia);
        double porc = Double.parseDouble(porcentaje);

        e.subeSueldo(porc);// Error <---------------------------

        if (Empleado.equalsIgnoreCase("E"))
        {

         e = new Empleado(nombre,sueld,añoInt,mesInt,diaInt);

            System.out.println(e.dameDatosEmpleado());
                    }

        if (Empleado.equalsIgnoreCase("J"))
        {

         e = new Jefatura(nombre,sueld,añoInt,mesInt,diaInt);
         Jefatura.asignarIncentivo(2570);

         System.out.println("El nombre del Jefe es : "+ e.dameNombre() + "\n" +
                            "El sueldo el Jefe es : " + e.dameSueldo() + "\n" +
                            "Alta es : " + e.dameFechaContrato()
                 );

                   }





    }



}

// Father Employee Class

  private String nombre;
    private  double sueldo;
    private Date altaContrato;
    private static int ID =100;



    public Empleado(String nom, double sue,int agno,int mes, int dia){

        nombre = nom;
        sueldo = sue;
        GregorianCalendar calendario = new GregorianCalendar(agno, mes-1,dia);
        altaContrato = calendario.getTime();




    }

    public   void subeSueldo(double porcen  ){

     sueldo *=(porcen/100)+1;

}

    public String dameDatosEmpleado(){

            ID++;

        return "Nombre del Empleado : " + nombre + "\n" + "Sueldo del Empleado : " + sueldo + "\n"+"Fecha de Alta : " + altaContrato + "\n" + "ID del Empelado : " + "E" +ID;
    }

    public  String dameNombre(){


        return nombre;
    }



    public Date dameFechaContrato(){

        return altaContrato;
    }



      public  double dameSueldo(){

    return sueldo;
     }

// Daughter Class Headquarters

 private static double incentivo;
private static int ID=100;

public Jefatura(String nombre,double sueldo,int año, int mes , int dia){

    super(nombre,sueldo,año,mes,dia);


}

public  static void asignarIncentivo(double b){

    incentivo = b;
}


public double dameSueldo(){

    double sueldoJefe = super.dameSueldo();

    return sueldoJefe+incentivo;

}

public  String dameNombre(){
    ID++;
    String nombreJefe = super.dameNombre();

    return nombreJefe + "\n" + "ID del Jefe : "+ "J"+ID;
}
introducir el código aquí
introducir el código aquí
    
asked by Junior Flores Alcantara 02.11.2018 в 23:10
source

1 answer

0

The problem is that you are trying to call subnuel de null (e). The misEmployees reference is initialized as [null, null, null], that's why you get the NullPointerException.

    
answered by 02.11.2018 в 23:40