user3217831
user3217831

Reputation: 11

Android Java: View cannot be applied to ()

I have a couple of EditText that I would like to stay hidden until made visible by one of many methods. To achieve this I was hoping to make my controls visible in it's own public void and call it back.

    public void showControls(View view) {
            EditText showV = (EditText) findViewById(R.id.vedit);
            EditText showH = (EditText) findViewById(R.id.hedit);

            showH.setVisability(view.VISABLE);
            showV.setVisability(view.VISABLE);
    }


    //calling on showControls
    public void onMethodOne (View view) {
        showControls();
    }

My output reads:

com.rayman.raysgame.MainActivity.showControls(android.view.View) in com.rayman.raysgame.MainActivity cannot be applied to ()

I don't really understand the output, so I am not sure how am I screwing up the code. I'd like to understand my mistake.

Upvotes: 1

Views: 7603

Answers (4)

ravindra.kamble
ravindra.kamble

Reputation: 1023

Change your code

showH.setVisability(view.VISABLE);
showV.setVisability(view.VISABLE);

to

showH.setVisability(View.VISIBLE);
showV.setVisability(View.VISIBLE);

Upvotes: 0

Avijit
Avijit

Reputation: 3824

You have to call the correct function by adding its argument showControls(View view). Its a very basic in programming language although.

And you have to call the findViewById by a proper way. It should be a instance of view.

Use this:

public void showControls(View view) {
      EditText showV = (EditText) view.findViewById(R.id.vedit);
      EditText showH = (EditText) view.findViewById(R.id.hedit);

      showH.setVisability(view.VISIBLE);
      showV.setVisability(view.VISIBLE);
}


//calling on showControls
public void onMethodOne (View view) {
     showControls(view);
}

Upvotes: 0

Apoorv
Apoorv

Reputation: 13520

You need to call showControls(view); instead of showControls(); as your method takes a View as an argument

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234795

You've declared showControls to take a View as an argument, but you're calling it with no arguments. You might want to change:

showControls();

to:

showControls(view);

However, I don't see that you are using the view itself in showControls. (You will also need to change the spelling of view.VISABLE to view.VISIBLE in that method.)

Upvotes: 1

Related Questions