0

사용자 지정 ImageView을 내 main.xml에 추가하려고 시도하지만 프로그램을 시작하면 강제 닫음으로 닫힙니다.사용자 지정 ImageView를 추가 한 후 강제 종료

XML :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" > 

    <test.testpkg.CustomImageView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center_vertical" 
      android:src="@drawable/bg"/> 

</LinearLayout> 

Java : 또한

package test.testpkg; 

import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.widget.ImageView; 

public class CustomImageView extends ImageView { 

    public CustomImageView(Context context) { 
     super(context); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
    } 
} 

나는 FC 후 디버거에서 프로그램을 시작하면 나는 단지이 얻을 : 당신이 천국 경우 link text

답변

3

디버거 쓸모가 Android의 소스 코드가 첨부되었습니다. 또한 ... logcat 출력을 제공하는 것이 더 유용합니다. 어쨌든, 나는 여러분이 생성자 중 하나를 놓치고 있다고 생각합니다. 시도해보십시오.

public class CustomImageView extends ImageView { 

public CustomImageView(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
} 

public CustomImageView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
} 
// rest of your code.... 
+0

두 번째 생성자가 필요합니다. – GeekYouUp

+0

네, 이제 작동합니다 .. 이상한 ADT는 1 개 매개 변수는 포함하지만 2 개 매개 변수는 포함시켜야한다고 말했습니다. 감사합니다! – Martin

+0

ADT가 아니 었습니다. Eclipse였습니다. – Cristian

관련 문제