0

main.xmlにカスタムImageViewを追加しようとしていますが、プログラムを開始すると強制終了して終了します。カスタム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の出力を提供する方が便利です。とにかく、私はあなたがコンストラクタの1つを欠いていると思います。試してみてください:

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

2番目のコンストラクタが必要です。 – GeekYouUp

+0

ええ、今それは動作している..奇妙なADTは、私は1つのパラメータではなく、2と一緒に含まれなければならないと言った。 – Martin

+0

それはADTだった、それはEclipseだった。 – Cristian

関連する問題