2010-07-11 2 views
0

그래서 때마다 내 안드로이드 응용 프로그램은 unexpectdly 중단이 코드를 실행하고 난 이유를 얻을 해달라고 ...Android 앱이 예상치 않게 멈추고 이벤트 핸들러를 실행하려고합니까?

import android.app.Activity; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.View.OnTouchListener; 
import android.widget.Button; 
import android.widget.TextView; 


public class TheStupidTest extends Activity { 


public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    final TextView text1 = (TextView) findViewById(R.id.TextView01); 
    text1.setText("well this works at least"); 

    Button yButton = (Button) findViewById(R.id.button_yellow); 
    yButton.setOnTouchListener(new OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      if (event.equals(MotionEvent.ACTION_UP)) { 
       text1.setText("You pressed the yellow button"); 
       return true; 
      } 

      return false; 
     } 


    }); 



    } 



} 
+0

Android 앱을 디버그하는 방법은 Pentium10의 게시물을 참조하십시오. http://stackoverflow.com/questions/3222608/android-error-the-application-has-stopped-unexpectedly-please-try-again/3223115# 3223115 – ccheneson

+0

DDMS와 logcat을 사용하여 문제를 확인하십시오. http://goo.gl/i9by –

+1

왜 버튼에 대한 'OnClickListener' 대신'OnTouchListener'가 필요합니까? – adamp

답변

1

1 문제가 MotionEvent.ACTION_UP 그래서 테스트가 정확하기 유형 int의 점이다, 당신은해야한다

if (event.getAction() == MotionEvent.ACTION_UP) { 
0

우선 전혀 OnTouchListener 정말 제외 Button에 해당하는 리스너가 아주 특별한 일을하고 있지된다. Button에 대해 OnClickListener을 구현해야합니다.

또한 ccheneson이 게시 한 것을 고려하십시오. 당신은 그것을 정확하게 비교하지 않습니다.

관련 문제