Question:
Java help! The operator == is undefined for the argument types void, int?
DoubleA
2011-06-02 18:14:25 UTC
I'm starting to get this error ever since constructing an interface in order to link everything to my Arraylist.

if(_coin.update() == 1) {

this is where it says the operator == is undefined

and this is my interface:

public interface Coin {
int nu = 1;
public void update ();
public void set();
}

class coins implements Coin{
public interface Coin {
public void update();
public void set();


}
}


which is linked to four different coin classes that more or less go like this:
class winter implements Coin {

int coinX, coinY, coinWidth, coinHeight;

winter ( int bX, int bY, int bW, int bH ) // The class constructor
{
coinX = bX;
coinY = bY;
coinWidth = bW;
coinHeight = bH;
}

int update()
{
int movementAmount; // Create and set a variable to hold the amount of white pixels detected in the area where the coin is
movementAmount = 0;

for( int y = coinY; y < (coinY + (coinHeight+1)); y++ ) { // For loop that cycles through all of the pixels in the area the coin occupies
for( int x = coinX; x < (coinX + (coinWidth-1)); x++ ) {

if ( x < width && x > 0 && y < height && y > 0 ) { // If the current pixel is within the screen bondaries
if (brightness(movementImg.pixels[x + (y * width)]) > 127) // and if the brightness is above 127 (in this case, if it is white)
{
movementAmount++; // Add 1 to the movementAmount variable.
}
}
}
}

if (movementAmount > 5) // If more than 5 pixels of movement are detected in the coin area
{
hitCoin++; // Add 1 point
return 1; // Return 1 so that the coin object is destroyed
}
else {


image(wCoin, coinX, coinY); // Draws the coin to the screen
return 0; // Returns '0' so that the coin isn't destroyed
}
}
}




-----
I'm fairly certain it's something to do with the new interface. Anyone got any ideas?
Three answers:
michael
2011-06-02 18:19:07 UTC
Your update method looks like it should return an int:

public void update (); >> public int update ();
?
2016-12-10 14:19:55 UTC
it truly is not how the || operator works. The || operator compares boolean values. It won't be able to evaluate int with something (a minimum of not in Java; in C and C++, it may, and behaves in a particular way even as doing so). Your mistake is in attempting to translate english straight away into software code. certain, in english we may be able to assert 'is the variety of vehicles equivalent to 119 or 189 or one hundred ninety'. In Java, notwithstanding, you should make each and each and every evaluation right into a boolean fee. So 'is the variety of vehicles equivalent to 119' is one boolean expression, and 'is the variety of vehicles equivalent to 189' is yet another, etc. So the code might want to somewhat look as if this: if (carnum == 119 || carnum == 189 || carnum == one hundred ninety || carnum == 191 || carnum == 192 || carnum == 193 || carnum == 194 || carnum == 195 || carnum == 221 || carnum == 780) There are various products of advice I supply to newbie programmers on right here with the stipulation that in the experience that they maintain on with all of them, they are going to be doing better than ninety 5% of the folk asking questions right here. this variety of things of advice is 'take not something with no interest'. You took with no interest that the syntax of Java may experience the syntax of your own community language, somewhat than reading Java's own documentation. i do not propose to be harsh; years in the past, I made an quite similar mistake, and it drove me nuts till I requested someone with extra experience and they defined what became going incorrect. All i'm keeping is, there's a lesson to be discovered right here, a lesson that is going previous in basic terms the scope of the || operator, and that i'm pointing it out so as that possibly you received't might want to be an element of the ninety 5% next time.
anonymous
2011-06-02 18:19:20 UTC
make sure update() (from coin.update()) returns a value (int in this case), you probably declared it something like

void update(){

...

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...