Я новичок в программировании, и я проводил некоторое время с Android. Я пытаюсь сделать простое приложение (только один простой класс), который вычисляет то, что вам нужно, чтобы попасть в ваш финал, чтобы получить определенный класс в классе. В 5-й линии, где я назначить кнопку calculate
, я получаю сообщение об ошибке: «Несколько маркеров на этой линииПочему Java думает, что этот метод объявлен, а не вызван?
- Return type for the method is missing
- Syntax error, insert ";" to complete
FieldDeclaration
- Syntax error on token ".", ... expected
- Syntax error on token ")", { expected after this
token"
Я был в состоянии успешно скомпилировать что-то очень похожее, но я не могу вспомнить, что Я изменил, чтобы не работать Вот мой простой класс:. любая помощь глубоко признателен
public class MainActivity extends Activity implements View.OnClickListener {
Button calculate;
EditText grade, wantedGrade, finalValue;
calculate = (Button) findViewById(R.id.button1);
grade = (EditText) findViewById(R.id.editText1);
wantedGrade = (EditText) findViewById(R.id.editText2);
finalValue = (EditText) findViewById(R.id.editText3);
@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;
}
/** calculates the grade and alerts the result */
public void reCalc(View view)
{
// calculate the grade
// (TotalGrade - (currentGrade * .8))/.2) = finalGrade
// where .8 and .2 are the values of the normal semester
// weight and final weight, respectively
double target;
double current = Double.parseDouble(grade.getText().toString());
double desired = Double.parseDouble(wantedGrade.getText().toString());
double finalWeight = Double.parseDouble(finalValue.getText().toString())/100;
double normalWeight = 1.0 - finalWeight;
target = (desired - (current * normalWeight))/finalWeight;
AlertDialog gradeMessenger = new AlertDialog.Builder(this).create();
gradeMessenger.setMessage("You need a " + target + " percent on the final to get a " + desired + " in the class.");
gradeMessenger.setCancelable(true);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}}
EDIT: я в настоящее время не имею достаточно репутации до голосования всех вас, но теперь это здорово работает, спасибо за помощь. Я очень благодарен.
Не делайте этого 'finalValue = (EditText) findViewById (R.id.editText3); 'как инициализатор поля. Он вернет 'null'. –