cannot find symbol
Hi,
can someone help me. appreciate some suggestions.
do not know why i'm getitng this error when compiling.
for some reason it's not recognising the method getVessels.
thanks
tony
package TpfrepUtilities;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.*;
publicclass TpfrepDBAO
{
private ArrayList shipping_lines;
private HashMap terminals;
private ArrayList vessels;
Connection con;
public TpfrepDBAO()throws Exception{
try{
InitialContext ic =new InitialContext();
Context envCtx = (Context) ic.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/MySQLDB");
con = ds.getConnection();
}catch (Exception ex){
thrownew Exception("Couldn't open connection to database: " +
ex.getMessage());
}
}
publicvoid remove(){
try{
con.close();
}catch (SQLException ex){
System.out.println(ex.getMessage());
}
}
public List getShipping_lines()throws SQLException
{
shipping_lines =new ArrayList();
try
{
String selectStatement ="select operator_code from line_operators";
PreparedStatement prepStmt = con.prepareStatement(selectStatement);
ResultSet rs = prepStmt.executeQuery();
while (rs.next())
{
//add operator code to array
shipping_lines.add(rs.getString(1));
}
prepStmt.close();
}
catch (SQLException ex)
{
System.err.println(ex.getMessage());
thrownew SQLException("Couldn't do query to database");
}
Collections.sort(shipping_lines);
return shipping_lines;
}
public HashMap getTerminals()throws SQLException{
terminals =new HashMap();
try
{
String selectStatement ="select database_id, terminal_name from terminals";
PreparedStatement prepStmt = con.prepareStatement(selectStatement);
ResultSet rs = prepStmt.executeQuery();
while (rs.next())
{
//add operator code to array
terminals.put(rs.getString(1),rs.getString(2));
}
prepStmt.close();
}
catch (SQLException ex)
{
System.err.println(ex.getMessage());
thrownew SQLException("Couldn't do query to database");
}
return terminals;
}
public List getVessels(String line_operator, String terminal)throws SQLException
{
vessels =new ArrayList();
try
{
String selectStatement ="select vessel from vessels where line_operator=? and terminal=?";
PreparedStatement prepStmt = con.prepareStatement(selectStatement);
prepStmt.setString(1,line_operator);
prepStmt.setString(2,terminal);
ResultSet rs = prepStmt.executeQuery();
while (rs.next())
{
//add operator code to array
vessels.add(rs.getString(1));
}
prepStmt.close();
}
catch (SQLException ex)
{
System.err.println(ex.getMessage());
thrownew SQLException("Couldn't do query to database");
}
Collections.sort(vessels);
return vessels;
}
}
===========================================
package TpfrepUtilities;
import java.util.*;
publicclass TpfrepDBBean
{
private TpfrepDBAO database =null;
private String operator="" ;
private String terminal="";
public TpfrepDBBean()
{
}
publicvoid setDatabase(TpfrepDBAO database)
{
this.database = database;
}
public List getShipping_lines()throws Exception{
return database.getShipping_lines();
}
public HashMap getTerminals()throws Exception{
return database.getTerminals();
}
publicvoid setOperator(String operator){
this.operator = operator;
}
publicvoid setTerminal(String terminal){
this.terminal = terminal;
}
public List getVessels()throws Exception{
return database.getVessels(operator,terminal);
}
}
error message :
C:\Servlets+JSP\struts-tpfrep\WEB-INF\classes\TpfrepUtilities>javac TpfrepDBBean
.java
TpfrepDBBean.java:37: cannot find symbol
symbol : method getVessels(java.lang.String,java.lang.String)
location: class TpfrepUtilities.TpfrepDBAO
return (List) database.getVessels(operator,terminal);
^
1 error
[8729 byte] By [
tonyca] at [2007-11-26 18:32:04]

Hello,I've just compiled the code you have given and it does not produce any errors.Try to delete the class files and recompile from scratch.Message was edited by: virusakos
Check your classpath on your javac command. Use the -classpath option to explicitly locate the "root" of the classpath under which the compiled TpfrepDBAO class can be found.That, at least, would be my first suggestion.
@masijadeCheck the error message.It says that it can't find a symbol. It does not complain about not finding a class.I don't think it's a classpath problem.
> Hi,
> can someone help me. appreciate some suggestions.
> do not know why i'm getitng this error when
> compiling.
>
> for some reason it's not recognising the method
> getVessels.
> thanks
>
> tony
>
>
> > package TpfrepUtilities;
>
> import java.sql.*;
> import javax.sql.*;
> import javax.naming.*;
> import java.util.*;
>
>
>
> public class TpfrepDBAO
> {
>private ArrayList shipping_lines;
> private HashMap terminals;
>private ArrayList vessels;
> Connection con;
>
>public TpfrepDBAO() throws Exception {
>try {
> InitialContext ic = new InitialContext();
> Context envCtx = (Context)
> ic.lookup("java:comp/env");
> DataSource ds = (DataSource)
> envCtx.lookup("jdbc/MySQLDB");
>con = ds.getConnection();
> atch (Exception ex) {
> throw new Exception("Couldn't open
> connection to database: " +
>ex.getMessage());
> }
>
>public void remove() {
>try {
> con.close();
> } catch (SQLException ex) {
> System.out.println(ex.getMessage());
>}
> public List getShipping_lines() throws
> s SQLException
> {
> shipping_lines = new ArrayList();
> ry
> {
> String selectStatement = "select
> t operator_code from line_operators";
> PreparedStatement prepStmt =
> = con.prepareStatement(selectStatement);
> ResultSet rs = prepStmt.executeQuery();
>while (rs.next())
> {
> //add operator code to array
>shipping_lines.add(rs.getString(1));
>
> prepStmt.close();
> catch (SQLException ex)
> {
> System.err.println(ex.getMessage());
> throw new SQLException("Couldn't do query to
> to database");
>}
> ections.sort(shipping_lines);
>return shipping_lines;
>
>
> public HashMap getTerminals() throws
> s SQLException {
> terminals = new HashMap();
>try
> String selectStatement = "select
> t database_id, terminal_name from terminals";
> PreparedStatement prepStmt =
> = con.prepareStatement(selectStatement);
> ResultSet rs = prepStmt.executeQuery();
>while (rs.next())
> {
> //add operator code to array
>
> terminals.put(rs.getString(1),rs.getString(2));
> }
> prepStmt.close();
>}
> h (SQLException ex)
> {
> System.err.println(ex.getMessage());
> throw new SQLException("Couldn't do query to
> to database");
>}
>return terminals;
>}
> public List getVessels(String line_operator, String
> terminal) throws SQLException
> {
> vessels = new ArrayList();
> ry
> {
> String selectStatement = "select vessel
> l from vessels where line_operator=? and
> terminal=?";
> PreparedStatement prepStmt =
> = con.prepareStatement(selectStatement);
> prepStmt.setString(1,line_operator);
> setString(2,terminal);
> ResultSet rs = prepStmt.executeQuery();
>
> while (rs.next())
> add operator code to array
>vessels.add(rs.getString(1));
>
> prepStmt.close();
> catch (SQLException ex)
> {
> System.err.println(ex.getMessage());
> throw new SQLException("Couldn't do query to
> to database");
>}
> ections.sort(vessels);
>return vessels;
>
>
> }
>
> ===========================================
>
>
> package TpfrepUtilities;
>
> import java.util.*;
>
>
> public class TpfrepDBBean
> {
>private TpfrepDBAO database = null;
> private String operator="" ;
>private String terminal="";
>
>public TpfrepDBBean()
> {
>}
>public void setDatabase(TpfrepDBAO database)
>{
>this.database = database;
>
>
> public List getShipping_lines() throws Exception
> {
>return database.getShipping_lines();
> public HashMap getTerminals() throws Exception
> {
>return database.getTerminals();
>
>public void setOperator(String operator) {
>this.operator = operator;
> }
>public void setTerminal(String terminal) {
>this.terminal = terminal;
> }
>
>public List getVessels() throws Exception {
>return database.getVessels(operator,terminal);
> }
>
> }
>
>
>
>
> error message :
>
> C:\Servlets+JSP\struts-tpfrep\WEB-INF\classes\TpfrepUt
> ilities>javac TpfrepDBBean
> .java
> TpfrepDBBean.java:37: cannot find symbol
> symbol : method
> getVessels(java.lang.String,java.lang.String)
> location: class TpfrepUtilities.TpfrepDBAO
> return (List)
> database.getVessels(operator,terminal);
>^
try this inside C:\Servlets+JSP\struts-tpfrep\WEB-INF\classes (Note the dot after -sourcepath)
javac -sourcepath . TpfrepUtilities/TpfrepDBBean.java
> C:\Servlets+JSP\struts-tpfrep\WEB-INF\classes\TpfrepUt
> ilities>javac TpfrepDBBean
> .java
> TpfrepDBBean.java:37: cannot find symbol
> symbol : method
> getVessels(java.lang.String,java.lang.String)
> location: class TpfrepUtilities.TpfrepDBAO
> return (List)
> database.getVessels(operator,terminal);
>^
you have to compile all java files at once
C:\Servlets+JSP\struts-tpfrep\WEB-INF\classes\TpfrepUtilities>javac *.java
Note: this is regarding the earlier post of mineI assume that you have all the source files inside WEB-INF/classes
> @masijade
>
> Check the error message.
> It says that it can't find a symbol. It does not
> complain about not finding a class.
> I don't think it's a classpath problem.
ClassNotFound comes during execution and indicates a classpath problem.
Symbol not found comes during compilation, and can also indicate a classpath problem.
> ClassNotFound comes during execution and indicates a
> classpath problem.
I wasn't talking about ClassNotFoundException
Sorry for not being accurate
> Symbol not found comes during compilation, and can
> also indicate a classpath problem.
True. But the error message will indicate symbol not found for a class.
In this case it does not.
In the error message he gets:
symbol : method getVessels(java.lang.String,java.lang.String)
If it was about a class then he would have get something like:
symbol : class TpfrepDBAO
> > ClassNotFound comes during execution and indicates
> a
> > classpath problem.
> I wasn't talking about ClassNotFoundException
> Sorry for not being accurate
>
> > Symbol not found comes during compilation, and can
> > also indicate a classpath problem.
> True. But the error message will indicate symbol not
> found for a class.
> In this case it does not.
>
> In the error message he gets:
> symbol : method
> getVessels(java.lang.String,java.lang.String)
> If it was about a class then he would have get
> something like:
> symbol : class TpfrepDBAO
It does if javac (for whatever reason, probably from making multiple compilation attempts in multiple different ways) finds the wrong version of an already compiled TpfrepDBAO, and simply removing the last compiled copies would not help this. He would either have to search for compiled version himself, or easier, simply tell javac where to find the correct version by giving it the classpath.
thanks guys for all the suggestions. really appreciate it. excellent.
I found 2 suggestions which worked for sure:
1) compiling both source files at the same time
javac *.java
2) using the -sourcepath switch. this also seems to be comiling both source files at the same time.
javac -sourcepath . TpfrepUtilities/TpfrepDBBean.java
do not know why this would have made all the difference.