2011-12-01 6 views
0

내가NullPointerException이 때 findingViewById

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.blindassistantmain); 

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    BlindTableLayout tableLayout = (BlindTableLayout) findViewById(R.id.blindTableLayout); 
    BlindButton btn = (BlindButton) findViewById(R.id.firstButton); 
    btn.setText("Lorem Ipsum"); //here is the nullpointer 
} 

내 XML이 사람이 내 코드에서 뭐가 잘못 알고 있나요이

<com.simekadam.blindassistant.ui.BlindTableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/blindTableLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="0px" 
    android:layout_margin="0px" 
    android:focusable="true" 
    android:stretchColumns="*" 

    android:background="@android:color/white" 
    > 
    <TableRow android:layout_weight="1"> 
     <com.simekadam.blindassistant.ui.BlindButton android:id="@+id/firstButton" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"/> 
     <com.simekadam.blindassistant.ui.BlindButton android:id="@+id/secondButton" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"/> 
    </TableRow> 
    <TableRow android:layout_weight="1"> 
     <com.simekadam.blindassistant.ui.BlindButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"/> 
     <com.simekadam.blindassistant.ui.BlindButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"/> 
    </TableRow> 
    <TableRow android:layout_weight="1"> 
     <com.simekadam.blindassistant.ui.BlindButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"/> 
     <com.simekadam.blindassistant.ui.BlindButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"/> 
    </TableRow> 

</com.simekadam.blindassistant.ui.BlindTableLayout> 

처럼 보이는 내에서 OnCreate 메소드의 마지막 줄에서 NullPointerException이 있나요? 감사합니다.

+0

깨끗이하고 프로젝트를 다시 빌드하십시오. – Petar

+0

귀하의 버튼이 사용자 정의 구성 요소 내부의 테이블 안에 있기 때문에 그 부분을 추측하고 있습니다. tableLayout 객체에 대한 호출을 통해 액세스 할 수 있습니다. –

답변

0

프로젝트를 정리하려고 했습니까? ("Project"-> "Clean") 가끔 이런 문제가 발생하면 도움이됩니다. 그리고 "자동으로 빌드"를 확인하는 것을 잊지 마십시오.

btw. R.java에서 버튼을 찾을 수 있습니까?

+0

나는 그것이 무엇을 의미하는지 확실하지 않다. 부식 코드 힌트는 나에게 그것을 제공한다. – simekadam

+0

그것은 여전히 ​​... 그리고 그것은 여전히 ​​작동하지 않는다. – simekadam

1

시도 :

BlindTableLayout tableLayout = (BlindTableLayout) findViewById(R.id.blindTableLayout); 
BlindButton btn = (BlindButton) tableLayout.findViewById(R.id.firstButton); 

당신이 당신의 tableLayout에서보기를 발견하고이 방법, 예컨대 tableLayout.findViewById (R.id.firstButton).

+0

나는 심지어 내 질문을 올렸다. 아직 거기에 – simekadam