У меня есть эти вещи, в задании я устанавливаю onTouchListener для моего ImageDraw, который расширяет класс ImageView, с этим слушателем я выполняю такие действия, как масштабирование и панорамирование жестами
Но в этом упражнении у меня естькнопку, но если установить onClickListener на кнопку, я получаю NullPointerException.
Без установки onClickListener все работает нормально.
Мой класс ImageDraw:
public class ImageDraw extends ImageView{
private Paint mPaint = new Paint();
List<Point> pts = new ArrayList<Point>() ;
public ImageDraw(Context context) {
super(context);
}
//used to send the location of the points to draw on the screen
//must be called before every redraw to update the points on the screen
public void SetPointsToDraw(List<Point> pts)
{
this.pts = pts;
}
public ImageDraw(Context context, AttributeSet attrs)
{
super(context,attrs);
}
public ImageDraw(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paintColor = mPaint;
paintColor.setColor(Color.YELLOW);
paintColor.setStrokeWidth(3);
if(pts.size() > 0)
{
canvas.drawCircle(pts.get(0).x, pts.get(0).y, 7, paintColor);
}
if (pts.size() > 1)
{
for (int i = 1 ; i < pts.size(); i++) {
paintColor.setColor(Color.YELLOW);
canvas.drawCircle(pts.get(i).x, pts.get(i).y, 7, paintColor);
paintColor.setColor(Color.RED);
canvas.drawLine(pts.get(i-1).x, pts.get(i-1).y, pts.get(i).x, pts.get(i).y, paintColor);
}
}
}
}
Отредактировано:
Здесь я устанавливаю onClickListener на кнопку, а здесь, где исключение - бросок.Точно на btnNew.SetOnTouchListener
Button btnNew = (Button) findViewById(R.id.btnNew);
try
{
btnNew.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Intent intent = new Intent(getApplicationContext(), NewWaypoint.class);
startActivity(intent);
return false;
}
});
}
catch(Exception e)
{
String teste = e.toString();
}