close

[Solved] Cannot invoke “” because “” is null

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error Cannot invoke “” because “” is null in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Cannot invoke “” because “” is null Error Occurs?

Today I am facing the following error Cannot invoke “” because “” is null in Java.

How To Solve Cannot invoke “” because “” is null Error ?

  1. How To Solve Cannot invoke “” because “” is null Error ?

    To Solve Cannot invoke “” because “” is null Error I think your problem is related with the lack of a @Component annotation in your BoardDao class. The component should have a @Component annotation to instantiate the singleton to be injected in your Service Layer.

  2. Cannot invoke “” because “” is null

    To Solve Cannot invoke “” because “” is null Error I think your problem is related with the lack of a @Component annotation in your BoardDao class. The component should have a @Component annotation to instantiate the singleton to be injected in your Service Layer.

Solution 1

I think your problem is related with the lack of a @Component annotation in your BoardDao class. The component should have a @Component annotation to instantiate the singleton to be injected in your Service Layer.

@Component
public class BoardDao extends SqlSessionDaoSupport{

    @Autowired
    SqlSessionTemplate session;

    public List<BoardDto> listboard(BoardDto dto) {
        System.out.println("dao.");
        List<BoardDto> result = session.selectList("boarddate.listboard", dto);
        return result;
    }

}

If the problem persist, you may try with the @Repository annotation. Sadly I haven’t used the class SqlSessionDaoSupport, so I don’t know exactly the best annotation for that.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read