現在、いくつかのエラーに直面しています。 「値」Androidスタジオ3.0のシンボル「値」を解決できません。カナリー8
「価値」記号を解決できません
あるの一つは赤で強調表示され、ビルドが失敗しました。私はjavaで単純なエラーを作ったと推測していますが、数日後にそれを見ていません。ここで
はMainActivity.javaのコードは次のとおりです。
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btnAdd;
private Button btnTake;
private TextView txtValue;
private Button btnGrow;
private Button btnShrink;
private Button btnReset;
private Button btnHide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get reference to all buttons in UI. Match them to all declared Button objects
btnAdd = (Button) findViewById(R.id.btnAdd);
btnTake = (Button) findViewById(R.id.btnTake);
txtValue = (TextView) findViewById(R.id.txtValue);
btnGrow = (Button) findViewById(R.id.btnGrow);
btnShrink = (Button) findViewById(R.id.btnShrink);
btnReset = (Button) findViewById(R.id.btnReset);
btnHide = (Button) findViewById(R.id.btnHide);
// listen for all the button clicks
btnAdd.setOnClickListener(this);
btnTake.setOnClickListener(this);
txtValue.setOnClickListener(this);
btnGrow.setOnClickListener(this);
btnShrink.setOnClickListener(this);
btnReset.setOnClickListener(this);
btnHide.setOnClickListener(this);
}
@Override
public void onClick(View view) {
// a local variable to use later
float size;
switch (view.getId()){
// case 1
case R.id.btnAdd:
value++;
txtValue.setText(""+ value);
break;
// case 2
case R.id.btnTake:
value--;
txtValue.setText(""+ value);
break;
// case 3
case R.id.btnReset:
value = 0;
txtValue.setText(""+ value);
break;
// case 4
case R.id.btnGrow:
size = txtValue.getTextScaleX();
txtValue.setTextScaleX(size + 1);
break;
// case 5
case R.id.btnShrink:
size = txtValue.getTextScaleX();
txtValue.setTextScaleX(size - 1);
break;
// last case statement with if-else
case R.id.btnHide:
if (txtValue.getVisibility() == View.VISIBLE){
// currently visible so hide it
txtValue.setVisibility(View.INVISIBLE);
// change text on the button
btnHide.setText("SHOW");
}else{
// hidden so show
txtValue.setVisibility(View.VISIBLE);
// change text on button
btnHide.setText("HIDE");
}
break;
}
}}
あなたは構文に誤りがありますかどうかを簡単に見てとることができた場合、私は非常に感謝するでしょう。
これは、あなたがAndroidを初めて使ったためにゼロになっています。このエラーは、一般的にJavaで、または多くの言語で正直にスローされます。あなたの変数 'value'は決して宣言されません –
' value'変数をインスタンス化します。 'int value = 0;' – Bajal