Skip to Main Content

Deutsche

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Null Pointer Exception

Just a NumAug 27 2018 — edited Aug 28 2018

Problem solved. That works well;

    public void getEmpFullName(ActionEvent ae) {

        DCBindingContainer Depbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Depdcib = Depbc.findIteratorBinding("DepartmentsView1Iterator");

        RowSetIterator Depiter = Depdcib.getRowSetIterator();

        Row departmentsRow = Depiter.first();

        DCBindingContainer Empbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Empdcib = Empbc.findIteratorBinding("EmployeesView1Iterator");

        RowSetIterator Empiter = Empdcib.getRowSetIterator();

        DCBindingContainer Jobbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Jobdcib = Jobbc.findIteratorBinding("JobsView1Iterator");

        RowSetIterator Jobiter = Jobdcib.getRowSetIterator();

        ArrayList<Integer> TotalSalary = new ArrayList<Integer>();

        ArrayList<Integer> MinSalary = new ArrayList<Integer>();

        ArrayList<Integer> MaxSalary = new ArrayList<Integer>();

        int empSalary = 0;

        int empMinSalary = 0;

        int empMaxSalary = 0;

        for (int i = 0; i < Depiter.getRowCount(); i++) {

              Row employeesRow = Empiter.first();

            String depId = departmentsRow.getAttribute(0).toString();           

            String depName = departmentsRow.getAttribute(1).toString();

                       

            for (int j = 0; j < Empiter.getRowCount(); j++) {

                try {

                    String empDepId = employeesRow.getAttribute(10).toString();

                    String salary = employeesRow.getAttribute(7).toString();

                    int tempSalary = Integer.parseInt(salary);

                    if (depId.equals(empDepId)) {

                        empSalary = empSalary + tempSalary;

                            Row jobsRow = Jobiter.first();

                        for (int k=0; k < Jobiter.getRowCount(); k++){                           

                            try{

                            String jobId = jobsRow.getAttribute(0).toString();

                            String empJobId = employeesRow.getAttribute(6).toString();

                            String maxiSalary = jobsRow.getAttribute(3).toString();

                            String miniSalary = jobsRow.getAttribute(2).toString();

                                int temMaxSalary = Integer.parseInt(maxiSalary);

                                int temMinSalary = Integer.parseInt(miniSalary);

                               

                                if(empJobId.equals(jobId)){

                                    empMinSalary = empMinSalary + temMinSalary;

                                    empMaxSalary = empMaxSalary + temMaxSalary;

                                }

                                }

                            catch (Exception e){}

                            jobsRow = Jobiter.next();

                        }                          

                        }                

                }

                catch (Exception e) {}

             employeesRow = Empiter.next();

            }       

                    TotalSalary.add(empSalary);

                    empSalary = 0;

                    MinSalary.add(empMinSalary);

                    empMinSalary = 0;

                    MaxSalary.add(empMaxSalary);

                    empMaxSalary = 0; 

                if (Depiter.hasNext()) {

                    departmentsRow = Depiter.next();

                } else {

                    break;

                }           

            System.out.println(depName + " " + "tot" + " : " + TotalSalary);

            TotalSalary.clear();

            System.out.println(depName +  " " + " min " + " : " + MinSalary);

            MinSalary.clear();

           System.out.println(depName +  " " + "max " + " : " + MaxSalary);

            MaxSalary.clear();

        }

    }

}

Hi guys,

Let me talk about what I want to do. I'm working on a UI kit which has 3 pages.(DepartmentsPage, EmployeesPage and JobsPage). DepartmentsId is a primary key which connects Dep and emp also jobId is primary which connects emp and jobs. So my purpose is calculating the total salaries of all departments and print it as an array. This part is done. The issue is one of the employee has no departments. While I tried to calculate min salary and max salary(they re attributes of jobs page) ı got a null pointer exception. I need to use try catch but I dont know where to use it.

I've been trying to print salary types to console but I got an error.   Maybe you guys show me how the fix it.

Here is my work.

  public void getEmpFullName(ActionEvent ae) {

        DCBindingContainer Depbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Depdcib = Depbc.findIteratorBinding("DepartmentsView1Iterator");

        RowSetIterator Depiter = Depdcib.getRowSetIterator();

        Row departmentsRow = Depiter.first();

        DCBindingContainer Empbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Empdcib = Empbc.findIteratorBinding("EmployeesView1Iterator");

        RowSetIterator Empiter = Empdcib.getRowSetIterator();

        DCBindingContainer Jobbc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        DCIteratorBinding Jobdcib = Depbc.findIteratorBinding("JobsView1Iterator");

        RowSetIterator Jobiter = Depdcib.getRowSetIterator();

        ArrayList<Integer> TotalSalary = new ArrayList<Integer>();

        ArrayList<Integer> MinSalary = new ArrayList<Integer>();

        ArrayList<Integer> MaxSalary = new ArrayList<Integer>();

        int empSalary = 0;

        int empMinSalary = 0;

        int empMaxSalary = 0;

        for (int i = 0; i < Depiter.getRowCount(); i++) {

            Row employeesRow = Empiter.first();

            String depId = departmentsRow.getAttribute(0).toString();

            String depName = departmentsRow.getAttribute(1).toString();

           

           

            for (int j = 0; j < Empiter.getRowCount(); j++) {

                try {

                    String empDepId = employeesRow.getAttribute(10).toString();

                    String salary = employeesRow.getAttribute(7).toString();

                    int tempSalary = Integer.parseInt(salary);

                    if (depId.equals(empDepId)) {

                        empSalary = empSalary + tempSalary;

                    }

                } catch (Exception e) {

                }

                employeesRow = Empiter.next();

            }

            for (int k = 0; k < Jobiter.getRowCount(); k++) {

                Row jobsRow = Jobiter.first();

                String jobId = jobsRow.getAttribute(0).toString();

                String empJobId = employeesRow.getAttribute(6).toString();

                try {

                    int TempMinSalary = Integer.parseInt(jobsRow.getAttribute(2).toString());

                    int TempMaxSalary = Integer.parseInt(jobsRow.getAttribute(3).toString());

                    if (jobId.equals(empJobId)) {

                        empMinSalary += TempMinSalary;

                        empMaxSalary += TempMaxSalary;

                    }

                } catch (Exception e) {

                }

                employeesRow = Empiter.next();

            }

            try {

                if (Depiter.hasNext()) {

                    TotalSalary.add(empSalary);

                    empSalary = 0;

                    MinSalary.add(empMinSalary);

                    empMinSalary = 0;

                    MaxSalary.add(empMaxSalary);

                    empMaxSalary = 0;

                    departmentsRow = Depiter.next();

                } else {

                    break;

                }

            } catch (Exception e) {

            }

            System.out.println(depName + "tot" + " : " + TotalSalary);

            TotalSalary.clear();

            System.out.println(depName + " min " + " : " + MinSalary);

            MinSalary.clear();

            System.out.println(depName + "max " + " : " + MaxSalary);

            MaxSalary.clear();

        }

    }

}

 

This post has been answered by Jim-D on Aug 27 2018
Jump to Answer
Comments
Post Details
Added on Aug 27 2018
1 comment
496 views