This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

Strange compiling problem

Troy Wang
Greenhorn

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.*;
import java.io.*;
public class DataRetrieval extends HttpServlet
{
private static Connection con = null;
private static Statement stmt = null;

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

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

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

private int i = 0;
try
{
ResultSet rst=null;
stmt = con.createStatement();
String queryString = "select TestID, SubID, RefID, Indicator, Title from ccTest where SubID='1' ;";
rst = stmt.executeQuery(queryString);
while (rst.next())
{
SequenceData temp = new SequenceData();
temp.setData(rst.getLong(1),rst.getLong(2),rst.getLong(3),rst.getLong(4),rst.getString(5));
SequenceData[i] = temp;
i++;
}
}catch(Exception ex)
{
ex.printStackTrace();

}
}

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

}
}
And I got error message like:
DataRetrieval.java:20: '}' expected.
{
^
DataRetrieval.java:22: Statement expected.
private String [] TitlePool = new String[10];
^
DataRetrieval.java:25: Type expected.
try
^
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="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
 
GeeCON Prague 2014
 
subject: Strange compiling problem