Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange compiling problem

 
Troy Wang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic