Я программирую приложение, но я всегда получаю это сообщение об ошибке: методы Void не могут вернуть значение И: Синтаксическая ошибка на токенах (-ах), неправильная конструкция (-ы) Об общедоступных строках Как я могу это решить?Android: много сообщений об ошибках Void
public void onClickGleichungAusrechnen(View view){
TextView tv = (TextView)findViewById(R.id.textView2);
TextView tv2 = (TextView)findViewById(R.id.textView3);
// beschreibt a*x^2 + b*x + c = 0
double a;
double b;
double c;
double a1;
double b1;
double c1;
a = a1;
b = b1;
c = c1;
public String toSignedString(double d){
// erzeugt String mit explizitem Vorzeichen
if (d >= 0) {
return("+ " + d);
} else {
return("- " + (-d));
}
}
public String toString() {
// erzeugt Textdarstellung der quadratischen Gleichung
String s = a + "*x^2 "+ toSignedString(b) + "*x "
+ toSignedString(c);
return s;
}
private double discriminant() {
// die Diskriminante der Gleichung
return(b*b/(4*a*a) - c/a);
}
private double[] getLinearSolution() {
// gib die Lösung der linearen Gleichung zurück
double[] result;
if (b != 0.0) {
// Normalfall der linearen Gleichung
result = new double[1];
result[0] = -c/b;
} else if (c != 0) {
// Gleichung lautet einfach c = 0, aber c != 0
// Widerspruch, also keine Lösungen
result = new double[0];
} else {
// b und c sind 0, die Gleichung lautet 0*x = 0
// alle Zahlen sind Lösung
// man kann aber nicht alle Zahlen zurückgeben!
// Notlösung: eine Lösung ausgeben und Warnungsmeldung dazu
tv.setText("WARNUNG: Gleichung 0*x = 0, alle x sind Lösung!");
result = new double[1];
result[0] = 1.0;
}
return result;
}
public double[] getSolution() {
// gibt Vektor mit den Lösungen zurueck
// berücksichtigt auch a = 0
if (a == 0.0) {
// lineare Gleichung, verwende entsprechende Lösungsroutine
return getLinearSolution();
}
// hier ist klar: a != 0
double a1 = -b/(2*a);
double d = discriminant();
double[] result;
if (d > 0) {
result = new double[2];
double dRoot = Math.sqrt(d);
result[0] = a1 + dRoot;
result[1] = a1 - dRoot;
} else if (d == 0) {
result = new double[1];
result[0] = a1;
} else {
// d < 0: es gibt keine (reelle) Lösung
result = new double[0];
}
return(result);
}
public void main(String[] args) throws IOException {
MainActivity qe1 = null;
// hole die Koeffizienten vom Benutzer
TextView tv = (TextView)findViewById(R.id.textView2);
TextView tv2 = (TextView)findViewById(R.id.textView3);
TextView tv3 = (TextView)findViewById(R.id.textView4);
TextView tv4 = (TextView)findViewById(R.id.textView5);
EditText ed1 = (EditText)findViewById(R.id.EditText01);
EditText ed2 = (EditText)findViewById(R.id.EditText02);
EditText ed3 = (EditText)findViewById(R.id.editText1);
float edz1 = Float.valueOf(ed1.getText().toString());
float edz2 = Float.valueOf(ed2.getText().toString());
float edz3 = Float.valueOf(ed3.getText().toString());
qe1 = new MainActivity(edz1, edz2, edz3);
tv.setText("Die quadratische Gleichung " + qe1);
double[] result = qe1.getSolution();
int count = result.length;
tv2.setText("hat " + count + " Lösungen");
if (count > 0) {
tv3.setText("" + result[0]);
}
if (count > 1) {
tv4.setText("" + result[1]);
}
}
}
Было бы здорово, если вы можете мне помочь, потому что я решил последнюю ошибку, но теперь я потерялся!
Спасибо, Dominik
PS: Пожалуйста, простите мой плохой английский, я сделал мой лучший :)
Спасибо за ваш ответ. Вы знаете, какой конструктор? – themrdomi
@themrdomi: У вас есть только один конструктор ('public MainActivity (double a1, double b1, double c1)'). Избавиться от этого. Также избавиться от 'main()', так как это тоже не будет использоваться. – CommonsWare