Sapp
Sapp

Reputation: 1803

Calling an integer to a method cast in a private void

I am in a single class, using 2 different methods.

In one method I have:

private void detect();
    int facesFound = detector.findFaces(bitmap565, faces);

detector, bitmap565 and faces are all defined in the same method.

In another method, I would like to call the value of facesFound.

So:

private void crop(){
if (facesFound > 1){

}

My issue is, I cannot access that integer from the method because it is cast locally. What is my best way to alter my code to call it?

Edit: to add method:

private final View.OnClickListener btnClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
   case R.id.action_button:
        crop();

So are you saying declare an integer at the top of my class that is defined as getting the integer passed back through my new private int detect() method?

Upvotes: 0

Views: 1874

Answers (1)

Wesley Wiser
Wesley Wiser

Reputation: 9851

Change detect() and crop() to:

private int detect()
{
    return detector.findFaces(bitmap565, faces);
}

private void crop(int numberOfFacesFound)
{
    if(numberOfFacesFound > 1)
    {

    }
}

Then, wherever you are calling crop() from:

int numberOfFacesFound = detect();
crop(numberOfFacesFound);

Upvotes: 1

Related Questions