android自定义视图在虚拟机中出现错误
我编写了一个简单的扩展视图类,代码如下:android自定义视图在虚拟机中出现错误,android,Android,我编写了一个简单的扩展视图类,代码如下: public class MyView extends View { public MyView(Context context) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated
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>
公共类MyView扩展了视图
{
公共MyView(上下文)
{
超级(上下文);
}
公共MyView(上下文、属性集属性){
超级(上下文,attrs);
//TODO自动生成的构造函数存根
}
受保护的void OnDraw(画布)
{
super.onDraw(帆布);
}
}
XML:
当进入虚拟机时。它显示了细分:
为什么会这样?我认为自定义视图应该很容易。我没有添加其他代码,它有错误。
编辑:logcat显示:
我想你需要另一个构造函数,至少,这是我在其他帖子中读到的
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
我想你需要另一个构造器,至少,这是我在其他帖子中读到的
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
你能找出上述异常的原因吗?请阅读粘贴在此处的stacktrace下方的内容(另外,尝试发布文本,而不是logcat视图中logcat>ctrl+C的屏幕截图,这样会复制它)。您能看到上述异常的原因吗?阅读粘贴在此处的stacktrace下方的内容(另外,尝试发布文本,而不是logcat视图中logcat>ctrl+C的屏幕截图,这样会复制它)。