incompatible types found : void, was ist falsch?
Ich bin versucht, zu schreiben eine Klasse, finden die nächsten zwei Vektoren und eine Summe.
Habe ich zu verstehen versucht, so hart aber ich kann nicht herausfinden, der Grund, warum ich diese Nachricht bekommen, es ist der einzige Fehler, den ich bekommen:
java:93: inkompatible Typen
gefunden : void
erforderlich: EDU.gatech.cc.ist.util.Vec2
Ergebnis = eins.add(zwei);
^
Zeile 93 ist am Ende der code, habe ich einige Pfeile zeigen es!
enter code here
package EDU.gatech.cc.is.clay;
import java.util.*;
import EDU.gatech.cc.is.clay.*;
import java.lang.*;
import EDU.gatech.cc.is.abstractrobot.*;
import EDU.gatech.cc.is.util.Vec2;
import EDU.gatech.cc.is.util.Units;
public class MAX_go_in_between extends NodeVec2
{
public static final boolean DEBUG = /*true;*/ Node.DEBUG;
private SocSmall abstract_robot;
public MAX_go_in_between(SocSmall ar)
{
abstract_robot = ar;
}
long last_spott = 0;
Vec2 result = new Vec2();
public Vec2 Value(long timestamp)
{
if (DEBUG) System.out.println("MAX_Avoid_walls: Value()");
if ((timestamp > last_spott) || (timestamp == -1))
{
if (timestamp != -1) last_spott = timestamp;
Vec2 one;
Vec2 two;
//array of Vec2 of all the opponents
Vec2[] list_opp = abstract_robot.getOpponents(timestamp);
//empty array of vec2 where will be put the opponents in front of the robot
ArrayList<Vec2> list_opp_in_front;
Vec2 temp;
//find which opponents are in front and put them in the arraylist
for(int i=0; i<list_opp.length; i++)
{
temp = list_opp[i];
if(temp.x >= 0.0)
{
list_opp_in_front.add(temp);
}
}
//get closest opponent and sets it to index 0
for(int i=1; i<list_opp_in_front.size()-1; i++)
{
temp = list_opp_in_front.get(i);
if(list_opp_in_front.get(0).r<temp.r)
{
list_opp_in_front.set(i, list_opp_in_front.get(0));
list_opp_in_front.set(0, temp);
}
}
//get second closest opponent and sets it to index 1
for(int i=2; i<list_opp_in_front.size()-1; i++)
{
temp = list_opp_in_front.get(i);
if(list_opp_in_front.get(1).r<temp.r)
{
list_opp_in_front.set(i, list_opp_in_front.get(1));
list_opp_in_front.set(1, temp);
}
//sum both vectors
one = list_opp_in_front.get(0);
two = list_opp_in_front.get(1);
=============>>>>
=============>>>> result = one.add(two);
}
}
return(result);
}
}
Here is the Vec2.add(Vec2) method:
public void add(Vec2 other)
{
x = x + other.x;
y = y + other.y;
r = Math.sqrt(x*x + y*y);
if (r > 0)
t = Math.atan2(y,x);
}
- Wie zu zeigen ist-Linie 93. Auch, was die Deklaration der Methode
Vec2.add(Vec2)
? - Bitte teilen Sie
add
Methode Erklärung vonVec2
.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Daraus die member-Funktion
add
nichts zurück, dass Sie inresult
. Mit einer Zeile wie:(wo
x
ist ein Mitglied von "das aktuelle Objekt" undother
ist das Objekt, das Sie hinzufügen, um es), es ist eine tote Gewissheit, dassone.Add (two)
soll ändernone
anstatt nur verwenden es in einer Berechnung.Statt:
müssen Sie wahrscheinlich etwas wie:
Wie pro Ihre Methode Erklärung
public void add(Vec2 other)
, die Sie hinzufügentwo
inone
. Soone
selbst ist ein Ergebnis, von daher gibt es keine Notwendigkeit, zurück.entfernen Sie einfach die return-Anweisung und behandeln
one
als Ergebnis-Objekt.