콘솔에서이 주석 다음에 장치 에뮬레이터 -5554 에서 시작 활동이 com.example.converter.MainActivity
인 경우 런타임에 오류가 발생했습니다. 불행히도 변환기가으로 중지되었습니다.불행히도 애플 리케이션이 중지되었습니다
내가 무엇을 할 수 있습니까?
public class mainactivity extends Activity {
private EditText text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// This method is called at button click because we assigned the name to the
// "OnClick property" of the button
public void onClick(View view) {
switch (view.getId()) {
case R.id.button1:
RadioButton celsiusButton = (RadioButton) findViewById(R.id.radioButton1);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radioButton2);
if (text.getText().length() == 0) {
Toast.makeText(this, "Please enter a valid number",
Toast.LENGTH_LONG).show();
return;
}
float inputValue = Float.parseFloat(text.getText().toString());
if (celsiusButton.isChecked()) {
text.setText(String
.valueOf(convertFahrenheitToCelsius(inputValue)));
celsiusButton.setChecked(false);
fahrenheitButton.setChecked(true);
} else {
text.setText(String
.valueOf(convertCelsiusToFahrenheit(inputValue)));
fahrenheitButton.setChecked(false);
celsiusButton.setChecked(true);
}
break;
}
}
// Converts to celsius
private float convertFahrenheitToCelsius(float fahrenheit) {
return ((fahrenheit - 32) * 5/9);
}
// Converts to fahrenheit
private float convertCelsiusToFahrenheit(float celsius) {
return ((celsius * 9)/5) + 32;
}
}
logcat + 관련 코드 만 입력하십시오. 또한,'onClick()'이 모든 버튼에 바인딩되는 것을 보지 못했습니다. 그 코드는 어디에 있습니까? – SudoRahul
레이아웃에서 onClick 메서드가 onClick 메서드로 지정 되었습니까? –
하나의 '.' 및 '?' 그 일을 해. '...'및 '????????'와 같은 채팅 언어를 사용하지 마십시오. –