Objekt.function() does not exist
in
Programming Questions
•
3 years ago
Hello everyone!
I got that problem, which I'm trying to describe as short as possible (with the exception of this introduction).
I got an own class Map (Object: mappe)
and an own class Feld ().
When trying to run the following, I get the error: "The function anziehenX does not exist" and its the same for anziehenY.
Since, I think, I make sure, the Object got that function, I guess it may be some safety mechanism of the compiler? If it is, is there a way to override it?
If not, I would be thankful for any suggestions =)
Thanks for reading,
toohuu
I got that problem, which I'm trying to describe as short as possible (with the exception of this introduction).
I got an own class Map (Object: mappe)
- class Map {
ArrayList Objekte;
Map() {
this.Objekte=new ArrayList();
}
boolean isType(int i, Class c) {
if (this.Objekte.get(i).getClass()==c) {
return true;
}
return false;
}
Object getObjekt(int i) {
return mappe.get(i);
}
}
and an own class Feld ().
- class Feld {
- float anziehenX (float speedx) {
return speedX;
}
float anziehenY (float speedy) {
return speedy;
} - }
When trying to run the following, I get the error: "The function anziehenX does not exist" and its the same for anziehenY.
Since, I think, I make sure, the Object got that function, I guess it may be some safety mechanism of the compiler? If it is, is there a way to override it?
If not, I would be thankful for any suggestions =)
- Feld f = new Feld;
class Feld = f.getClass();
float speedy=0; - float speedx=0;
if (mappe.isType(0,Feld)) {
speedx=mappe.getObjekt(i).anziehenX(speedx);
speedy=mappe.getObjekt(i).anziehenY(speedy);
}
Thanks for reading,
toohuu
1