[Android/안드로이드]java.lang.ClassCastException: android.widget.LinearLayout 에러
Tech develop/Android 2014. 8. 10. 14:31반응형
아주 간단한 Button 한개가 추가된 Simple Project를 작성하고
Button Click Handler를 구성하기 위해 다음과 같이 code를 작성했다.
===========================================================================
1 public void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 4 try { 5 setContentView(R.layout.main); 6 btnObject = (Button)this.findViewById(R.id.button1); <=== exception 7 btnObject.setOnClickListener(this); 8 } 9 catch (Exception e) { 10 e.printStackTrace(); 11 } 12 } 13===========================================================================
그런데 이러허게 간단한 code가 왠걸...컴파일 후 실행하면
exception(id=830007829856)이 발생되면서 프로그램이 죽어버린다.
흠.. 몇시간의 구글링을 통해 알아낸 결과로는
|
그러나 구글링을 통해 알아낼 해결방법은 고작
|
그렇지만 위의 code에서와 같이 벌써 coding되어 있음에도 exception이 발생된다는것은
여전히 main layout이 생성되지 않았다는 것을 의미한다.
몇시간의 삽질 끝에.. main.xml에 다음과 같이 어이가 없는 상황이 발생되어 있음을 알게되었다.
===========================================================================
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@+id/linearLayout1" <== 이 라인이 추가. 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 9 <Button 10 android:id="@+id/button1" 11 android:layout_width="fill_parent" 12 android:layout_height="wrap_content" 13 android:text="Button" /> 14 15 </LinearLayout>===========================================================================
반응형
'Tech develop > Android' 카테고리의 다른 글
[Android/안드로이드] .9.png(9patch) 사용 법 (0) | 2014.08.10 |
---|---|
[Android/안드로이드]ExpandableListView 그룹 닫기 메소드 (0) | 2014.08.10 |
[Android/안드로이드]Url에 있는 사진 Bitmap으로 변환하기 (0) | 2014.08.10 |
[Android/안드로이드]Internet 연결여부 확인 (0) | 2014.08.10 |
[Android/안드로이드]Keyboard 보이기/숨기기 구현 (0) | 2014.08.10 |