프로그래밍/안드로이드

[안드로이드] Binary XML file line #13: Error inflating class fragment 해결 방법

가카리 2013. 10. 28. 20:17
반응형

이 에러는 해결할 첫번째 방법

 

xml Layout에 커스텀 뷰를 넣을 경우는 대부분은 아시겠지만..

Packgage : com.test

Class : CustomComponent


위를 main.xml에 넣을려구 할 경우

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<com.test.CustomComponent 

android:id="@+id/customId"

    android:layout_width="match_parent" 

    android:layout_height="wrap_content" />


 

</LinearLayout>


다음과 같이 작성 한다..

 


하!지!만! 이렇게 작성할 경우 가장 많이 보이는 이런 비슷한 에러를 볼 수 있다.

Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.test.Com~~~~~

열심히 구글링을 해본 결과...

역시나 답은 있었다.


생성자에 꼭 AttributeSet을 넣어야 하는것이다.

         public  CustomComponent (Context context) {

super(context);

}

public  CustomComponent (Context context,AttributeSet attr) {

super(context,attr);

}

꼭 위의 빨간색 같이 생성자를 넣어줘야만 하며!!

만약 클래스를 상속 받으면 부모 클래스에도 위와 같은 생성자를 넣어줘야합니다.

 

출처:http://joshy21.com/weblog/25

 

아니면

 

두번째 방법은

 

숫자는 res/layout/레이아웃.xml 파일의 Line Number를 의미하는데, 

해당 라인넘버에 지정된 태그명에 해당하는 클래스가 없을 경우에 발생한다.


클래스의 경로가 정확한지 확인해보자.

 

 

저는 두번째 방법으로 해결을 했네요..... 모두 오타 조심합시다!

 

반응형