• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object scope within a try/catch block

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to compile the following code:

public static void main(String args[])
{
try
{
RandomAccessFile r = new RandomAccessFile("rtest.txt","rw");
}
catch (FileNotFoundException e)
{
}
try
{
r.seek(0);
}
catch (IOException e)
{
}
}

...produces the following error...

--------------------------- Compiler Output ---------------------------
HelloWorld.java:20: cannot resolve symbol
symbol : variable r
location: class HelloWorld
r.seek(0);
^
1 error


Is it because the scope of the object referenced by r is limited to within the curley braces of the first try/catch statement?
 
Jimmy Blakely
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind.....just figured out that it is the variable with the limited scope. thx anyways
reply
    Bookmark Topic Watch Topic
  • New Topic