2010-03-20 13 views
1

에뮬레이터에서 라디오 버튼을 누르면 언제든지 강제 종료됩니다!라디오 버튼을 클릭 할 때 강제 종료

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button b = (Button)this.findViewById(R.id.btn_confirm); 
     b.setOnClickListener(this); 
     RadioButton radio_ctf = (RadioButton) findViewById(R.id.radio_ctf); 
     RadioButton radio_ftc = (RadioButton) findViewById(R.id.radio_ftc); 
     radio_ctf.setOnClickListener(this); 
     radio_ftc.setOnClickListener(this); 
    } 
    @Override 
    public void onClick(View v) 
    { 
    TextView tv = (TextView)this.findViewById(R.id.tv_result); 
    EditText et = (EditText)this.findViewById(R.id.et_name); 
    RadioButton radio_ctf = (RadioButton) findViewById(R.id.radio_ctf); 
     RadioButton radio_ftc = (RadioButton) findViewById(R.id.radio_ftc); 
    double y = 0; 
    int x = Integer.parseInt(et.getText().toString()); 
    if(radio_ctf.isChecked()) 
    { 
     y = ((double)x * 1.8) + 32; 
    } 
    if(radio_ftc.isChecked()) 
    { 
     y = ((double)x - 32) * 0.555; 
    } 
    String text = "Result:" + y; 
    tv.setText(text); 
+1

아마 무언가가 null의 : 문자열을 검증하기

는 게시물 다음 읽어 보시기 바랍니다. 디버거와 LogCat을 사용하여 문제를 찾으십시오. – Pentium10

답변

2

먼저 DDMS 콘솔에서 오류 (DDMS 버튼, Eclipse를 사용하는 경우)를보십시오. 이러한 오류에는 많은 이유가 있습니다. 실제로 처리되지 않은 Java 예외가 있음을 의미합니다. 당신 때문에 당신이있는 Integer.parseInt에 전달할 값으로 예외를 얻고있다

2

내 생각 엔()

당신은 그것을 구문 분석하기 전에 문자열을 확인해야합니다. Java library to check whether a String contains a number without exceptions

+0

문자열의 유효성을 어떻게 검사합니까? 사용할 수있는 기능이 있습니까? – neos300

+0

몇 가지 방법이 있습니다.이 게시물 확인 : http://stackoverflow.com/questions/1163615/java-library-to-check-whether-a-string-contains-a-number-without-exceptions – Baget

관련 문제