-1
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    chustilla();}


public void chustilla (View v){ //Do anything }

When I compile it gives me a problem in the parameter of chustilla(). What can I do to call this method from onCreate?

PD: If I put "this" or "null" inside the brackets it doesn't work aswell

user3481906
  • 1
  • 1
  • 1

6 Answers6

2

chustilla(View) requires a View reference to be passed as a parameter so it won't work if you don't pass a View reference to it. According to what is done inchustilla(View) (best known to you) you can pass it a View from the layout (Also, best known to you).

EdmDroid
  • 1,350
  • 1
  • 11
  • 25
1

Your method public void chustilla (View v) expects to be passed a View object. But in onCreate() You simply call chustilla(). You need pass it a view object.

EdmDroid
  • 1,350
  • 1
  • 11
  • 25
mbiokyle
  • 152
  • 9
1
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    chustilla(a);
}


public void chustilla (Int a)
{
    //your code
}
Raj Bedi
  • 164
  • 3
  • 14
0

Try the following:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    chustilla();
}


public void chustilla ()
{
    //Do anything 
}
likeitlikeit
  • 5,563
  • 5
  • 42
  • 56
Ahmad
  • 73
  • 1
  • 5
0

or use this for example:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String s;
    chustilla(s);
}


public void chustilla (String v)
{ //write code here }
Ahmad
  • 73
  • 1
  • 5
-1

example parameter "new View(this)" :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    chustilla(new View(this));}


public void chustilla (View v){ //Do anything }
Stefan Kanev
  • 311
  • 4
  • 7