2013-02-19 7 views
0

다음 코드 삽과는 을 발생시킵니다. findByName 메서드에 의해 throw됩니다. PlayerComponentGroupList를 찾을 수없는 것 같지만 그 이유는 모르겠습니다.findByName NullPointerException

어떻게 생성 된 을 참조 할 수 있습니까?

protected void beforeMain(Form f) { 
    super.beforeMain(f); 
    try { 
     findPlayerComponentGroup(f).addComponent(getItems("Player")); 
    } catch (IOException ex) { 
     throw new RuntimeException(ex.getMessage()); 
    } 

} 

private Container getItems(String order) throws IOException { 
... 
final Container rows = new ComponentGroup(); 
... 
rows.setName("PlayerComponentGroupList"); 
    return rows; 
} 

protected void onMain_PlayerContainerButtonSortNameAction(Component c, ActionEvent event) { 
    super.onMain_PlayerContainerButtonSortNameAction(c, event); 
    try { 
     findPlayerComponentGroup().removeComponent(findByName("PlayerComponentGroupList", Display.getInstance().getCurrent()))); 
... 
} 
+0

예외를 throw하는 방법은 무엇입니까? 디버거에서 실행하고 null을 반환하는 이유는 무엇입니까? –

+0

죄송합니다.이 포퍼를 공식적으로 작성하지 않았습니다 : findByName .... 질문 수정 – Megachip

답변

0

findByName() 그런 식으로 작동하지 않습니다. GUI 빌더로 작성된 구성 요소에서만 작동하므로 매우 빠릅니다 (그렇지 않으면 매우 느린 구성 요소 트리를 재귀 적으로 검색해야합니다).

구성 요소에 대한 포인터를 유지하고 제거해야합니다.

+0

간단한 예제를 추가 할 수 있습니까? THX – Megachip

+0

해결 방법으로 GUI 빌더를 통해 빈 컨테이너를 추가 했으므로 필요한 구성 요소를 모두 제거하고 readd를 사용할 수 있습니다. 이것이 받아 들일만한 해결책이되기를 바라십니까? – Megachip

+0

예. –