RedComet
RedComet

Reputation: 11

Error when accessing variable from another class

I am trying to use a variable from another class. however, it shows an error at the following code:

public class ItemDetailActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState, String[] args) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_item_detail);
      Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
      setSupportActionBar(toolbar);
      DummyContent Position = new DummyContent();
      int picCheck = Position.getPos();
    }
}

Here is the getter:

public int getPos(int position) {
    return position;
}

Can you show me what my problem here is?

The error:

Error:(31, 32) error: method getPos in class DummyContent cannot be applied to given types;

required: int

found: no arguments

reason: actual and formal argument lists differ in length

Upvotes: 0

Views: 72

Answers (1)

GhostCat
GhostCat

Reputation: 140641

Here:

int picCheck = Position.getPos();

Intending to use:

public int getPos(int position)

Notice that one line wants an int parameter; and that the other line doesn't give one.

And the real answer here is: the compiler message already tells you so. Required int, found: no arguments.

Meaning: java compiler messages are easy to read most of the time.

Thus the answer beyond the simple left-over here: if your Java skills are on a level that makes it hard to understand such messages, you are most likely overburdening yourself at this point by trying to do Android programming.

Upvotes: 4

Related Questions