java - Android Drawing app crashing -
i new android programming , started out simple drawing app. found , collated code after browsing code doesn't seem work. app opens having white screen doesn't when touch , drag. no lines or seen. white screen.
here code.
package com.drawing.emeraldsoul.drawingapp; import android.app.activity; import android.content.res.resources; import android.content.context; import android.graphics.canvas; import android.graphics.color; import android.graphics.paint; import android.graphics.path; import android.util.attributeset; import android.view.motionevent; import android.view.view; class myview extends view { // setup initial color private final int paintcolor = color.black; // defines paint , canvas private paint drawpaint; private path path = new path(); public myview(context context, attributeset attrs) { super(context, attrs); setfocusable(true); setfocusableintouchmode(true); setuppaint(); } // setup paint color , stroke styles private void setuppaint() { drawpaint = new paint(); drawpaint.setcolor(paintcolor); drawpaint.setantialias(true); drawpaint.setstrokewidth(5); drawpaint.setstyle(paint.style.stroke); drawpaint.setstrokejoin(paint.join.round); drawpaint.setstrokecap(paint.cap.round); } @override protected void ondraw(canvas canvas) { canvas.drawpath(path, drawpaint); } @override public boolean ontouchevent(motionevent event) { float pointx = event.getx(); float pointy = event.gety(); // checks event occurs switch (event.getaction()) { case motionevent.action_down: path.moveto(pointx, pointy); return true; case motionevent.action_move: path.lineto(pointx, pointy); break; default: return false; } // force view draw again postinvalidate(); return true; } } public class mainactivity extends activity { public mainactivity() { super(); } }
the main file mainactivity , hence, added public class empty constructor. if try adding whole paint code in mainactivity class extending view, app crashes, doesn't start, error saying "no empty constructor found". coded way. not sure if right.
can please tell me going wrong?
thanks lot, in advance, esash
the app crashes, doesn't start, error saying "no empty constructor found".
i think wants empty constructor view class.
public myview() { // todo: maybe place here? } public myview(context context, attributeset attrs) { super(context, attrs); setfocusable(true); setfocusableintouchmode(true); setuppaint(); }
but real problem lies in have no oncreate
activity. , not need empty constructor anyways.
public class mainactivity extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.yourlayoutwithmyview); // todo: put layout here } }