이 당신이 내가 얻을 이렇게하지 내가 아주되었다 네 내 변수를 매번 정의에서 볼 수 있듯이자바 IntelliJ에 오류
package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText text;
private EditText text2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (EditText) findViewById(R.id.editText1);
text2=(EditText)findViewById(R.id.result);
}
// 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.radio0);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
RadioButton KelvinButton=(RadioButton) findViewById(R.id.radio2);
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()) {
text2.setText(String
.valueOf(convertFahrenheitToCelsius(inputValue)));
celsiusButton.setChecked(true);
} else {
text2.setText(String
.valueOf(convertCelsiusToFahrenheit(inputValue)));
fahrenheitButton.setChecked(false);
celsiusButton.setChecked(true);
if(KelvinButton.isChecked())
{
text2.setText(String.valueOf(convertoKelvin(inputValue)));
}
}
break;
case R.id.button2:
RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
RadioButton KelvinButton=(RadioButton) findViewById(R.id.radio2);
float inputValue = Float.parseFloat(text.getText().toString());
if (text.getText().length() == 0) {
Toast.makeText(this, "Please enter a valid number",
Toast.LENGTH_LONG).show();
return;
}
if (fahrenheitButton.isChecked()) {
text2.setText(String
.valueOf(convertFahrenheitToCelsius(inputValue)));
celsiusButton.setChecked(true);
} else {
text2.setText(String
.valueOf(convertCelsiusToFahrenheit(inputValue)));
fahrenheitButton.setChecked(true);
if(KelvinButton.isChecked())
{
text2.setText(String.valueOf(convertoKelvin(inputValue)));
}
}
break;
case R.id.button3:
RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
RadioButton KelvinButton=(RadioButton) findViewById(R.id.radio2);
float inputValue = Float.parseFloat(text.getText().toString());
if (text.getText().length() == 0) {
Toast.makeText(this, "Please enter a valid number",
Toast.LENGTH_LONG).show();
return;
}
if (KelvinButton.isChecked()) {
text2.setText(String
.valueOf(convertFahrenheitToCelsius(inputValue)));
celsiusButton.setChecked(true);
} else {
text2.setText(String
.valueOf(convertCelsiusToFahrenheit(inputValue)));
fahrenheitButton.setChecked(false);
celsiusButton.setChecked(true);
if(KelvinButton.isChecked())
{
text2.setText(String.valueOf(convertoKelvin(inputValue)));
}
}
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;
}
private float convertoKelvin(float celsius)
{
return ((celsius+273)) ;
}
}
완료되지 않은 내 안드로이드 응용 프로그램 내 코드입니다 오류가 "값은 내가 잘못하고 있어요 initialised.What되지 않았을 수 있습니다.
당신이 궁금해하는 경우, 내 코드가 아닌 완벽한 건이 오류에 빨아하고 계속됩니다 번이 고정되어
아래에있는 라인은 당신이 오류가있는 것처럼 보일 것? –
at if (celsiusButton.isChecked()). 컴파일러 경고가 아니며 IDE 경고입니다. – deception1