18
findViewById ()는 다른 구성 요소가 아닌 레이아웃 XML의 사용자 정의 구성 요소에 대해 null을 반환합니다.
나는 res/layout/main.xml다음 요소와 다른 요소를 포함하고 있습니다. <some.package.MyCustomView android:id="@+id/foo" (some other params) /> <TextView android:id="@+id/boring" (some other params) /> 내 활동의 onCreate에서 다음을 수행합니다. setContentView(R.layout.main); TextView boring = (TextView) findViewById(R.id.boring); // ...find other elements... MyCustomView foo = (MyCustomView) findViewById(R.id.foo); if (foo == null) { Log.d(TAG, "epic fail"); } 다른 요소는 …