Results 1 to 8 of 8
- 10-25-2011, 03:15 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
cannot find symbol error, defined inside private method
hello, i am new to java and am looking for help with this problem. thank you very much to anyone who wouldn't mind helping me out.
i need to use variables (r,x1,x2,etc.) inside the main method of my program that were previously defined inside a private method.
is this possible, and if so how would i do this?
example:
private static double dist(double x1, double y1, double x2, double y2){
double r;
r = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
return r;
}
public static void main(String() args){
forceX[body]= F*((x1-x2)/r);
forceY[body]= F*((y1-y2)/r);
}
if it isn't possible, are there any changes i can make so that i'll be able to use these values later on?Last edited by sp725; 10-25-2011 at 03:17 AM.
- 10-25-2011, 03:54 AM #2
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
Re: cannot find symbol error, defined inside private method
You can only call private methods from within their class. So as long as you're calling it from the same class, then yes you can.
For the "cannot find symbol" error, please post the exact error message with the code that's causing it.
- 10-25-2011, 04:25 AM #3
Re: cannot find symbol error, defined inside private method
That is not 100% correct. The following code will not compile.
Java Code:public class Test { public static void main(String[] args) { XYZ.dostuff(); } } class XYZ { public static void dostuff() { showMe(); } private void showMe() { System.out.println("Hello World"); } }
- 10-25-2011, 04:35 AM #4
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
- 10-25-2011, 04:39 AM #5
Re: cannot find symbol error, defined inside private method
No its not. The code is calling showMe from within the XYZ class.
- 10-25-2011, 04:44 AM #6
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
- 10-25-2011, 04:46 AM #7
Re: cannot find symbol error, defined inside private method
But according to your comment I can do that because it is within the class. But we know that you cannot do that which brings us back to my point that your comment was not 100% correct.
- 10-25-2011, 04:47 AM #8
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
Re: cannot find symbol error, defined inside private method
Last edited by Solarsonic; 10-25-2011 at 04:51 AM.
Similar Threads
-
int cannot be dereferrenced, cannot find symbol method add
By felixnoriel in forum JCreatorReplies: 2Last Post: 03-08-2011, 03:08 PM -
HELP! can't find symbol-method
By Jack9333 in forum New To JavaReplies: 2Last Post: 03-04-2011, 01:48 AM -
this is the error i get: cannot find symbol method parseString(java.lang.String)
By Elcliff in forum New To JavaReplies: 10Last Post: 12-22-2010, 01:12 AM -
cannot find symbol - method iterator()
By D.Calladine in forum New To JavaReplies: 1Last Post: 11-30-2010, 12:13 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks