包含自定义类库出错!(JAVA)(100分)

  • 主题发起人 主题发起人 AIHUA
  • 开始时间 开始时间
A

AIHUA

Unregistered / Unconfirmed
GUEST, unregistred user!
自定义类
package MyNa.utils;
import java.io.*;
public class Logger {
}
编译通过 JAVAC Logger.java -->logger.class
调用如下
package MyNa.utils;
import MyNa.utils.*;
public class LookerUpper {
}
提示如下
lookerUpper.java:19: cannot resolve symbol
symbol : class Logger
location: class MyNa.utils.LookerUpper
Logger lg;
**** 我已经在classpath中填写了logger.class的路径。
为什么还有问题??
 
class MyNa.utils.LookerUpper
把MyNa.utils改成myna.utils试试
 
你是怎么调用的,给出代码
 
所有的MyNa.utils改成myna.utils 结果还是不行
题是如下
lookerUpper.java:17: cannot resolve symbol
symbol : class Logger
location: class myna.utils.LookerUpper
Logger lg;
^
lookerUpper.java:19: cannot resolve symbol
symbol : class Logger
location: class myna.utils.LookerUpper
public LookerUpper(String drvrName, String dbName,String qString,Logger L) throws SQLException
^
2 errors
 
代码如下
filename::::Logger.java
package myna.utils;
// logger class
import java.io.*;
import myna.utils.*;
// communiCate with database
public class Logger { // may be shared across threads.
static String fileProp="myna.utils.logger.file";
static String debugProp="myna.utils.logger.debuglevel";
static String defaultFileName="dbLog.log";
String fileName;
int debugLevel;
// simply on or off, in this version;
// we use separate Logger objects for err, admin.
public Logger(String fName){
fileName=fName;
debugLevel=Integer.parseInt(System.getProperty(debugProp,"1"));
}
public Logger(){
this(System.getProperty(fileProp,defaultFileName));
}
public synchronized void setFileName(String fName){
fileName=fName;
}
public synchronized void setDebugLevel(int N){
debugLevel=N;
}
public synchronized void setDebug(boolean B){
debugLevel=B?1:0;
}
public synchronized void setDebug(String S){
setDebug((new Boolean(S)).booleanValue());
}
public synchronized void clearLog(){
if(debugLevel<=0)return;
try{
PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
//String S=MiscDate.todaysDate();
String S = "";
f.println(S);
f.close();
}catch(IOException e){}
}
public synchronized void logIt(String S){
if(debugLevel<=0)return;
try{
PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
f.println(S);
f.close();
}
catch(IOException e)
{
}
}
public synchronized void logIt(String S,Throwable ex){
if(debugLevel<=0)return;
try{
PrintWriter f=new PrintWriter(new FileWriter(fileName,true));
f.println(S);
ex.printStackTrace(f);
f.close();
}catch(IOException e){}
}
public static String stackTrace(Throwable ex){
StringWriter sw=new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}

 
filename:::: lookerUpper.java
package myna.utils;
import java.sql.*;
// communicate with database
import myna.utils.*;
// Logger saves administrative info to file
// MiscDB utility functions
public class LookerUpper {
Connection dbConn=null;
PreparedStatement dbPrepStmt=null;
String theQueryString=null;
// "SELECT then
UMBER,THEADDR FROM PHONEBOOK WHERE then
AME=?;";
String driverName=null;
// "sun.jdbc.odbc.JdbcOdbcDriver";
String dbUrl=null;
// ="jdbc:odbc:IQTEST";
String theUser="usr";
String thePwd="pwd";
Logger lg;

public LookerUpper(String drvrName, String dbName,String qString,Logger L) throws SQLException
{
driverName=drvrName;
try
{
Class.forName(driverName);
}
catch(Exception E)
{
E.printStackTrace();
L.logIt("LookerUpper failed with "+E);
return;
}
dbUrl=dbName;
theQueryString=qString;
lg=L;
dbConn=DriverManager.getConnection(dbUrl,theUser,thePwd);
dbPrepStmt=dbConn.prepareStatement(theQueryString);
lg.logIt("LookerUpper connected to "+dbUrl);
}
public void close(){ // ignore exceptions, try to close up.
lg.logIt("LookerUpper.close()");
try
{
if(dbPrepStmt!=null)
dbPrepStmt.close();
}
catch(java.lang.Exception E)
{
lg.logIt("error in close: ",E);
}
finally{lg.logIt("finalize: closing?");
try
{
if(dbConn!=null)dbConn.close();
lg.logIt("finalize: closed");
}
catch(java.lang.Exception E)
{
lg.logIt("error in close: ",E);
}
}
}
public ResultSet lookup(String V){ // lookup value V;
specifically
lg.logIt("looking up: "+V+";
with query="+theQueryString);
try
{ // initialization of dbPrepStmt in init.
dbPrepStmt.setString(1,V);
if(!dbPrepStmt.execute())
{
lg.logIt("no result set");
return null;}
return dbPrepStmt.getResultSet();
}
catch (java.lang.Exception ex)
{
/* ex.printStackTrace();
*/
lg.logIt("lookup: "+ex);
return null;
}
}
}
 
请给出lookerUpper.java的代码,
主要是17,19行出错。
 
我给代码前添加了所属文件名字
 
我在jb7中编译没有错误,
我想应该是classpath 没有设置正确
 
我在JCreator中也编译通过了
你是不是没有把这两个文件放在正确的路径中
例如
%classpath%/myna/utils
直接在classpath中填写logger.class的路径是不行的
 
a! 我还以为。。。
不知道呀
 
多人接受答案了。
 
后退
顶部