2012-11-13 22 views
1

错误我编写一个简单的扩展视图类,代码如下:机器人定制视图在虚拟机

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> 

当条目中的虚拟机。它显示了故障: enter image description here

这是为什么?我认为自定义视图应该很容易。我没有添加其他代码,它有错误。 编辑:logcat显示: enter image description here

+0

你能看到以上例外的原因吗?读一下你粘贴在这里的堆栈跟踪(另外,尝试发布文本而不是logcat的屏幕截图> ctrl + C在logcat视图中将复制它)。 –

回答

1

我认为你需要另一个构造函数,至少,这就是我在其他职位阅读。

public MyView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
}