makotoのブログ

やりたいこと。
写真の上に何かを描く。

方針
Viewをextensして自作 PracticeView を作る。
xmlのlayoutに入れて、setContextViewで描画。

行き詰まり
02-13 02:46:45.181: ERROR/AndroidRuntime(635): java.lang.RuntimeException: Unable to start activity ComponentInfo{yeele.com.androidbasic/yeele.com.androidbasic.AndroidBasic}: android.view.InflateException: Binary XML file line #14: Error inflating class yeele.com.androidbasic.PracticeView


原因
Viewのconstractor!
public class PracticeView extends View {

private Context context;
public PracticeView(Context context){
super(context);
this.context = context;

}

上のように書いていたのが間違い
reference をよく確認したら、xmlに使う場合は、以下のようなconstroctorを
使うようにすればいいと解釈。
 



View
(Context context, AttributeSet attrs)
Constructor that is called when inflating a view from XML.


備考
もともとはlayoutにImageViewで写真を挿入、
これをプログラムから取得して、その上にラクガキを書きたかったが、
現時点では方法がわからず、viewに絵を描きたい場合は自作でView
を拡張子、お絵かきできるように拡張するしかないと結論づけた。