0

I have two methods in the same class, the first method isgetEventByEventId and the second method is addEventUserRealtionMapping. I need to call the getEventByEventId method from the addEventUserRelationMapping method. How can I get that done?

public EventBO getEventByEventId(long eventId) throws UserServiceException {
        try {
            EventDO eventDO = eventDAOImpl.getEventByEventId(eventId);
            EventBO eventBO = mapper.mapEventDOToBO(eventDO, new EventBO());
            return eventBO;
        } catch (UserDataException uExp) {
            throw new UserServiceException("Error while getting event for event id   " + eventId, uExp);
        }
    }

public int addEventUserRealtionMapping(ArrayList<UserBO> userBOs, long eventId) throws UserServiceException {

        List<EventUserRelationDO> totalAddedCount;
        ArrayList<UserDO> userDOs = new ArrayList<>();
        try {
            for (UserBO userBO : userBOs) {
                UserDO userDO = mapper.mapUserBOToDO(userBO, new UserDO());
                userDOs.add(userDO);
            }
            EventBO eventBO =new EventBO();
            eventBO =getEventByEventId(eventId);//I am try that while call method1 but it doesn't work
            MessageBO messageBO = new MessageBO();
            messageBO.setEventId(eventBO.getEventId());
            messageBO.setEventTitle(eventBO.getText());
            messageBO.setMessage(eventBO.getText());
            messageBO.setRingeeUserId(eventBO.getRingeeUserId());
            messageBO.setMessageType(IRingeeConstants.MESSAGE_TYPE_INVITATION);
            totalAddedCount = eventDAOImpl.addEventUserRelationMapping(userDOs, eventId);
            if (totalAddedCount.size() == userDOs.size()) {
                manageMessageService.sendMessageToGroup(userBOs, messageBO);
            }
        } catch (UserDataException dExp) {
            throw new UserServiceException(" exception while adding user relationship for eventId " + eventId, dExp);
        }
        return totalAddedCount.size();
    }
8
  • 1
    you don't know how to call a method? Commented Oct 26, 2015 at 7:40
  • I know how to call a method but I here I want to call and set the return value to eventBO..I don't know how to do that. Commented Oct 26, 2015 at 7:43
  • seems to be cyclic recursive method calls? am I stating the obvious? Commented Oct 26, 2015 at 7:43
  • Do they belong to the same class? What's the problem in calling a method? Commented Oct 26, 2015 at 7:44
  • I'd suggest modifying the question to say that, it's not at all obvious that's what you want. Also, the title needs to be edited, as methods can't be nested, so "a method in another method" doesn't make sense in Java. Commented Oct 26, 2015 at 7:45

2 Answers 2

2

You can call it using this.methodName() or directly by writing the methodName()

class ClassName{

  public void method1(){
  }

  public void method2(){

     this.method1(); // called the first method of the same class
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can call function easily but you will need to put getEventByEventId inside try catch or throw UserServiceException form addEventUserRealtionMapping

if you have infinite loop it seem that you mapEventDOToBO calls addEventUserRealtionMapping inside it and you are try getEventByEventId again so that it causes infinite loop you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.