Reputation: 79
I want draw on canvas some picture, line, ring etc. but i want make this only on small area, on part screen. I have this layout "activity_main"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.example.canavstest.Draw2d
android:id="@+id/game"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_gravity="center_vertical|center_horizontal" />
and main class
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
and class where i painting
public class Draw2d extends View{
public Draw2d(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.BLUE);
canvas.drawPaint(paint);
}
}
when i try to start my application i get next error
09-25 21:06:43.925: E/AndroidRuntime(28370): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.canavstest/com.example.canavstest.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class com.example.canavstest.Draw2d
what i doing wrong?
Upvotes: 1
Views: 1666
Reputation: 11190
Looks like you spelt your packageName incorrectly. Check your AndroidManifest.
com.example.canavstest.Draw2d
Should probably be
com.example.canvastest.Draw2d
Notice the spelling of canvas
Edit: Also, you have not implemented the constructor that the LayoutInflater calls. Add this.
public Draw2d(Context context, AttributeSet attrs){
super(context, attrs);
}
Upvotes: 4