Reputation: 29
I have got this simple method written in a custom class Numbers.java
:
public class Numbers {
public int add (int n,int m) {
int i = n + m;
return i;
}
}
But when I try to call this method in my main
-class like so:
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
int i = add(4, 6);
}
I get an red error sign on the line number of int i = add(4, 6);
saying:
cannot find symbol
symbol: method add(int,int)
location: class Main
Also, when I wrote the method in my custom class I got a yellow warning sign on the line number where I declared the method saying "Missing Javadoc". I did some googling on this and found out that you were supposed to add certain URL's to your Java Platform Manager under the tab Javadoc, but as far as I can see all of my URL's are in place. I include a picture of it down below:
I have no idea what is wrong, and I'm grateful for any help!
Upvotes: 0
Views: 960
Reputation: 2280
Your method btnAddActionPerformed
is in class Main
, and is trying to call a function add
, which is in a different class. Try this:
public class Numbers {
public static int add (int n,int m) {
int i = n + m;
return i;
}
}
And:
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
int i = Numbers.add(4, 6);
}
Upvotes: 1