I have an Activity CropActivity, that uses my own written View CropView. CropView extends SelectorView (also selfwritten), and SelectorView extends ImageView.
When starting the CropActivity, a NoSuchMethodException is thrown. When using the SelectorView for the CropActivity, no error is thrown, any ideas?
The Cropview class public class CropView extends SelectorView {
public CropView(Context context) {
super(context);
initCropView();
}
private void initCropView() {
setmPaintColor(Color.WHITE);
setsMinimumSize(metrics.densityDpi);
setsTouchBuffer(metrics.densityDpi / 3);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (getmLeftTop().equals(0, 0))
resetPoints();
// draw the points on the screen; one in every corner and one in the center
canvas.drawRect(getmLeftTop().x, getmLeftTop().y, getmRightBottom().x, getmRightBottom().y,
getmPaint());
canvas.drawCircle(getmLeftTop().x, getmLeftTop().y, 40, getmPaint());
canvas.drawCircle(getmLeftTop().x, getmRightBottom().y, 40, getmPaint());
canvas.drawCircle(getmRightBottom().x, getmLeftTop().y, 40, getmPaint());
canvas.drawCircle(getmRightBottom().x, getmRightBottom().y, 40, getmPaint());
canvas.drawCircle(getmCenter().x, getmCenter().y, 10, getmPaint());
}
Selectorview snippet
public SelectorView(Context context) {
super(context);
initSelectorView();
}
public SelectorView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
initSelectorView();
}
public SelectorView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initSelectorView();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
/**
* Initializes the cropview and variables.
*/
private void initSelectorView() {
mPaint.setStyle(Style.STROKE);
mPaint.setStrokeWidth(5);
mLeftTop = new Point();
mRightBottom = new Point();
mCenter = new Point();
mScreenCenter = new Point();
mPrevious = new Point();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
switch (eventaction) {
// set the touch point
case MotionEvent.ACTION_DOWN:
mPrevious.set((int) event.getX(), (int) event.getY());
break;
oncreate from CropActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crop);
mContext = this;
mCropView = new CropView(this);
mFile = new File(getIntent().getStringExtra("imgpath"));
mBitmaps = new ArrayList<Bitmap>();
mTasks = new ArrayList();
mNumberOfCores = Runtime.getRuntime().availableProcessors();
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setTitle("Enhancing image");
mBitmapDrawable = null;
mBitmapDrawable = (BitmapDrawable) Drawable.createFromPath(mFile.getAbsolutePath());
mCropView = (CropView) findViewById(R.id.image_preview);
mCropView.setImageDrawable(mBitmapDrawable);
mCropButton = (Button) findViewById(R.id.button_crop);
Custom views inflated via XML need the following constructors:
ViewName(Context)
ViewName(Context, AttributeSet)
ViewName(Context, AttributeSet, int)
You only have the first one and I guess the exception is about the second one being missing in your CropView
.