Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'cannot resolve symbol' error

Status
Not open for further replies.

purpledawn

Programmer
Jun 21, 2001
50
US
Hi. I am just learning Java, coming to it with some VB and VBA, and couple obscure languages. I am trying to compile a class and I am getting an error that I can't figure out.

I had both JDK 1.2 and JDK 1.3 installed on my machine. The class I am trying to compile was written for 1.2. It compiled fine when both versions were installed, but it wouldn't run (ClassDefNotFoundError). I uninstalled 1.2, and now I get a 'cannot resolve symbol' error when accessing a (.zip) package when I try to compile the class. It should work with 1.3, right? Why did it compile before, but not now?

Any help is appreciated. Thanks.
 
this has nothing to do with 1.2 and 13 being both installed. rather when you compile in Java, all the classes that you have used or referenced in any of your new classes have to be in the classpath.

Example, in you program you:

import org.dix.tools.MiddleFinger;

class MyClass extends MiddleFinger {

blah blah

}

you have to ensure the the compiler understands what middle finger is by allow it to find the class. either set the CLASSPATH environmental variable so that the location of this class or whatever archive contains this class is represented or when you compile use the -classpath switch and specify it there.

Good luck!

Go Java!

Dix
 
Thanks for your reply. I had the classpath variable set to the .zip archive when it was compiling before and I hadn't changed that. Since then I've looked around and set 'CLASSPATH' in different ways, without success.

This is part of the code I'm compiling:
Code:
// You need to import the java.sql package to use JDBC
import java.sql.*;

// We import java.io to be able to read from the command line
import java.io.*;

class JdbcCheckup
{
  public static void main (String args [])
       throws SQLException, IOException
  {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Prompt the user for connect information
    System.out.println ("Please enter information to test connection to the database");
    String user;
    String password;
    String database;

...

  }
}

This is one command I've tried:
Code:
C:\oracle\ora81\jdbc\lib>javac -classpath . JdbcCheckup.java
and got the same error message:
Code:
JdbcCheckup.java:19: cannot resolve symbol
symbol  : class OracleDriver
location: package driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                                                       ^
1 error
In this case, I've placed the file at the base of the package structure and tried to compile it from there using '.' for classpath. I've tried this using both a .zip package and also by expanding the package; I get the same error in both cases.

Any other suggestions?
 
Notice how you never imported the Oracle driver. You are trying to use a class that the compiler does not understand - oracle.jdbc.driver.OracleDriver

the correct way to write this section is...

import java.sql.*;

class JdbcCheckup
{

Connection conn;

JdbcCheckup() throws ClassNotFoundException {
//load the oracle driver class
Class.forName( "oracle.jdbc.driver.OracleDriver" );
}

public static void main (String args [])
throws Exception
{
//remember to instantiate yourself, hardest thing to
//understand coming from c++ and vb
JdbcCheckup checkup = new JdbcCheckup();
//get the user name, password, dsn
...
//create the connection
conn = DriverManager.createConnection( url , user , password );
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "select * from mytable" );
while( rs.next() ) {
//print stuff...
}
)
}

make sure oracle's package, which if i remembered correctly is classes.zip is in the compile classpath

and remember the oracle type 4 driver url string is really tricky, read the doc, you can't mis any :

good luck

Dix
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top