当前位置:编程学习 > wap >>

Android 自定义view在虚拟机出错

我写了最简单的继承View的类:代码如下

public class MyView extends View
{

   public MyView(Context context)
   {
       super(context);
   }
    
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

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

XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


       <com.main.sufaceview.MyView
           android:id="@+id/myview"
           android:layout_width="300dp"
           android:layout_height="300dp"
           android:background="@drawable/tt"/>  

</RelativeLayout>


结果一进入虚拟机就出现奔溃


这是什么情况,自定义的view应该是最简单的吧,没加别的代码都出错 --------------------编程问答-------------------- logcat 显示什么? --------------------编程问答-------------------- --------------------编程问答-------------------- 没人帮下吗? --------------------编程问答-------------------- 我觉得你应该再创建一个构造函数:
public MyView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
}
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,