This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have a program with try, catch, finally blocks in it. I do not understand why the compiler says that 1. UserDirectory.java:34: Illegal start of type try (line 34 is flagged in the code below) 2. UserDirectory.java:84: <identifier> expected } (line 84 is also flagged in the code below) Please help.
Hi, The code between line 34 and line 84 is outside of any method or initialization block, so the compiler assumes "try" is supposed to be the return type of a method. You've got methods declared inside the try block, too, which are also illegal; you can only define methods at class scope, and you can only put code (try blocks, for example) inside a method or an initialization block. I'm really confused about what you're trying to do in a lot of places:
Who is supposed to call the isUserLogon() method?
At line 32, you initilize a member _username with a call to fixId() passing the member username as an argument. But username isn't initialized in the constructor, so when this code runs, you'll get a NullPointerException.
What should initiate the execution of the code in the big try block?
I hope I'm not insulting you, but I'm guessing you're not an experienced Java programmer, yes? You might want to start out with an introductory Java book like Head First Java before jumping into something as involved as working with Struts (this is derived from something in Struts in Action, yes?)