2011-04-14 3 views
0

나는 이러한 것들을 가지고 있는데, 나는이 청취자와 함께 ImageView 클래스를 확장하는 ImageDraw에 onTouchListener를 설정했다. 확대/축소 및 팬 제스처로 팬안드로이드 - 버튼과 같은 액티비티의 확장 ImageView에 클릭 리스너 생성하기

하지만이 작업에는 버튼이 있습니다. 버튼에 onClickListener를 설정하면 NullPointerException이 발생합니다.

onClickListener를 설정하지 않으면 모든 것이 잘 동작합니다. 내가 버튼에 OnClickListener를 설정 곳

다음

이며, 그 여기 어디 테 excpetion는 던져입니다 :

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); 
     } 
    } 


} 

}

편집 :

내 ImageDraw 클래스입니다. 정확히 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(); 
    } 
+0

오류를주는 코드를 넣을 수 있습니까? ' – JQCorreia

+0

레이아웃에있는 경우 레이아웃이 비정상적으로 늘어난 것처럼 보입니다. 단추에 onClickListener를 설정하는 위치에 대한 자세한 정보가 필요합니다. – chaitanya

+0

NullPointerException이 throw되는 위치를 알고 계십니까? – shihpeng

답변

0

내 추측에 지금은 활동의 내용보기를 설정하지 않는다는 것입니다. 스택 추적 및 활동 코드를 게시 할 수 있습니까?

0

나는 비슷한 질문을 만났지만, 나는 활동에서 setcontentView를 잊어 버렸다는 것을 발견했다. 그것이 당신을 도울 수 있기를 바랍니다.

관련 문제