File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Simple problem with calling methods in static main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple problem with calling methods in static main method" Watch "Simple problem with calling methods in static main method" New topic
Author

Simple problem with calling methods in static main method

Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
I know this is simple I just can't get around this problem for whatever reason. All I am trying to do is call multiple similar methods within the main method. I have looked at examples online and most say to make the method static and there should not be a problem, but I am still having a problem. To make matters worse, this code used to work just fine, but I had 9 main methods, and it was just ugly. Here is what I have:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

So what is the simple problem?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Haha sorry. My compiler gives me the error "cannot find symbol - class insertion_srt1"
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Brian Mart wrote:Haha sorry. My compiler gives me the error "cannot find symbol - class insertion_srt1"


Nothing in the code you've shown looks like it would cause that problem, although I'm not a compiler and I'm not going to spend much time looking for it.

If you tell us which line it was complaining about, that will take some of the guesswork out of it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
By the way, you ought not to have a class called insertion_srt1. Putting things like no 1 and no 2 can be confusing to read because the brain does not readily understand what no 1 and no 2 mean. Also you should use CapitalLetters, write the words out in full, and avoid the characters _$, with one exception. Have a look at these naming conventions, which can prevent a lot of confusion. Package names follow slightly different conventions and the _ symbol is permitted.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

That's probably not the complete error message compiler gives you.
You might miss import statement for FileNotFoundException class (assuming Random_10 and Reverse_10 are declared somewhere before you use them as parameters of method call).


The quieter you are, the more you are able to hear.
Ruud Smith
Greenhorn

Joined: Feb 05, 2004
Posts: 11

Besides possible other problems in your code and the naming convention, as mentioned before, there seems to be a '_'-symbol missing between 'insertion' and 'srt1' on line 5.
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Ok I have been researching for days and I still cannot find a reason that I am getting this error. I will delete this post as soon as I get an answer, as it is an assignment. And please ignore naming conventions for the time being, I am just trying to figure out why I am getting this "cannot find symbol - class insertion_srt1" error on line 7. This is a simple call of a class from the main class, correct? Thank you tremendously in advance for any help.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Brian Mart wrote:Haha sorry. My compiler gives me the error "cannot find symbol - class insertion_srt1"


No, that's not the error it's giving, at least not with the most recent code you've posted.

Please copy and paste the exact, complete error message. But before doing that, please look at it closely. It's telling you exactly what's wrong, and it's not lying.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
Brian Mart wrote: . . . a reason that I am getting this error.
Which error? What error? What is the actual error message? I tried the code you posted and did not get the error message you are going on about.
I will delete this post as soon as I get an answer . . .
No, you won’t. Once you post something here, it is public knowledge, and it can be retrieved. It might also be helpful to others. So we do not have a policy of deleting posts.

If you post the actual error message you are getting at present, we can help you.
And please ignore naming conventions for the time being . . .
As well as making you sound impatient, that sort of comment will lose you marks. You will doubtless get marks for style of code, which includes naming conventions.
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Ok, my bad. First of all, I deleted all of the naming conventions you guys called me out on before in order to simplify the problem. I understand that my names were confusing, I am just looking for help as to why I cannot call this variable. Sorry for seeming impatient, I just have been looking for answers to this problem on my own for days and I am incredibly frustrated, just looking for a little guidance. I was unaware of the "no delete" policy as well. Forgive me.

Anyway, the exact error message is "cannot find symbol - variable Random_10" on line 7

Clearly just having trouble understanding how to call variables into the main class. Maybe I am reading it wrong, but from what I can see around the web, I have it right (although I know I must be missing something)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Campbell Ritchie wrote:
Brian Mart wrote:And please ignore naming conventions for the time being . . .
As well as making you sound impatient, that sort of comment will lose you marks. You will doubtless get marks for style of code, which includes naming conventions.


An unwillingness to follow the conventions suggested will also make people less likely to want to read your code for two reasons. 1) It's harder to read, and 2) It sounds like you're saying, "My time is more valuable than yours." The idea is to encourage people to want to help you, not to leave them thinking it isn't worth their time.

Just something to think about for future posts.
Brian Mart
Ranch Hand

Joined: Apr 17, 2012
Posts: 34
Yes I understand. I worded that post poorly. I meant it as, "ok, removing all other components of the code that would create problems with naming conventions..." not "please ignore how terribly I am writing this". The original code was terrible, I know. But the revised, shortened code was just the brass tax of one class. Sorry again for the confusion and never meant to create all this hostility
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Brian Mart wrote:
Anyway, the exact error message is "cannot find symbol - variable Random_10" on line 7


Good. So that tells us that you're trying to us a variable named Random_10 in a place where no such variable exists. If it's not obvious why you're getting that error, then you need to go back and review your lessons on varible scope. In summary, though, local variables only exist in the nearest enclosing block in which they're declared, one copy for each method call; non-static member variables exist anywhere the object does--basically any constructor, non-static method, or non-static initailizer block--one copy for each object; and static member variables exist throughout the class, one copy shared by the whole class.

So your simplest solution to the compiler error would be to define a variable in main to pass to the method. Note, though, that then you'll have another problem. You're declaring two Random_10 variables in your sort method.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Brian Mart wrote:never meant to create all this hostility


There's no hostility. We just feel rather strongly about nipping bad habits in the bud.

An believe me, it is truly to your own benefit to get into good habits now. If you tell yourself, "Okay, I know it should be done that way, but I don't have time to change it now, I'll do it right next time," you've taken the first step toward developing a bad habit. Do that a few more times and it will be that much harder to break it.

Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

And the clue to the solution of your problem was in the answer I posted two days ago.
assuming Random_10 and Reverse_10 are declared somewhere before you use them as parameters of method call

If you read it carefully, you wouldn't need to look for answer for days, as you say.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple problem with calling methods in static main method
 
Similar Threads
Code working fine, but input file is garbled on output
Symbol can't be found
Need help with reading multiple lines from a txt file and putting them into an array
Array problem
Hard time filling array