Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method visibility inside a try block

 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several times I have run into this issue. I want to call another method in the same class. I cannot do this when inside a try block. I can send some sample code, but I think perhaps it is just a general question that does not need code to answer. The error message is the compiler cannot resolve symbol (name of method I wish to call).
Thanks.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you had better post some example code. AFAIK, you can call any method you want from inside a try block. What prompted the claim that you can't? Have you had compiler errors when you tried it before?
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as it's not something I didn't know about visibility and try blocks, I'll look for the problem in the code. Thanks.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best to post the code, Betty. My first guess would be that you left out an import statement, or are misspelling the name of a class or method.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...or maybe the method name was spelled correctly, but the parameter list wrong.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That at least will get you a more useful error message. Something like:
foo(int,int) in MyClass cannot be applied to (java.lang.String)
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys, but at least this time I think it was a case sensitivity error. ( on my part! )
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ron Newman:
That at least will get you a more useful error message. Something like:
foo(int,int) in MyClass cannot be applied to (java.lang.String)

Sun's Java v1.4 compiler does give such a nice error message, but other compilers, such as the v1.3 compiler that shipped with JBuilder 7, just give the "method not found" or "no such method" error message.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message I posted is from the 1.3.1 compiler on MacOS X.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, yes... I've been told repeatedly that Macs are better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic