File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Illegal Start of the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Illegal Start of the "try" Block?!" Watch "Illegal Start of the "try" Block?!" New topic
Author

Illegal Start of the "try" Block?!

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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?)


    [Jess in Action][AskingGoodQuestions]
    JiaPei Jen
    Ranch Hand

    Joined: Nov 19, 2000
    Posts: 1309
    Thank you, Ernest. You correctly pointed out my problems. I do not have much hands-on experience in IT. Nonetheless, I am learning a lot (in Java, Servlet, JSP, and Struts) by constructing a web site.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Illegal Start of the "try" Block?!
     
    Similar Threads
    Struggling With Passing Data Between Data Access Class, Business Bean, and Controller
    I Have Problem To Separate Business Logic From Front Controller
    DataSource issues
    Populate JavaBean With Data Fetched From the Database
    NullPointerException At Statement stmt = conn.createStatement();