File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Strange compiling problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Strange compiling problem" Watch "Strange compiling problem" New topic

Strange compiling problem

Troy Wang

Joined: Jan 31, 2001
Posts: 6
HI, Everyone:
I got a strange compiling message, please any expert to explain to me why that. Here is my sample code:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class DataRetrieval extends HttpServlet
private static Connection con = null;
private static Statement stmt = null;

public void init(ServletConfig config) throws ServletException
//con = HelperClass.getConnection();

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException

private String [] TitlePool = new String[10];

private int i = 0;
ResultSet rst=null;
stmt = con.createStatement();
String queryString = "select TestID, SubID, RefID, Indicator, Title from ccTest where SubID='1' ;";
rst = stmt.executeQuery(queryString);
while (
SequenceData temp = new SequenceData();
SequenceData[i] = temp;
}catch(Exception ex)


public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException

And I got error message like: '}' expected.
^ Statement expected.
private String [] TitlePool = new String[10];
^ Type expected.
3 errors
I thought my code shouldn't have compiling problem so I can't understand the message.
Many thanks.
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Local variables declared inside a method do not take access modifiers (e.g., "private"). Instead of
private String [] TitlePool = new String[10];
private int i = 0;
just write
String [] TitlePool = new String[10];
int i = 0;

Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
I agree. Here's the link:
subject: Strange compiling problem
jQuery in Action, 3rd edition