目的:在一个自己写的类A 里调用另一个已经编译过的类B。A和B在同一个目录下。使用TOMCAT。
在编译类A的时候出错,刚刚看JAVA三天,现在还有点搞不清晨面的关系,请大侠们帮忙看看。
编译类A时出错信息:
C:\Documents and Settings\Shaun>javac C:\jakarta-tomcat\webapps\Assignment1\WEB-
INF\classes\mypack\ShowBalance.java
C:\jakarta-tomcat\webapps\Assignment1\WEB-INF\classes\mypack\ShowBalance.java:47
: cannot resolve symbol
symbol : class BankCustomer
location: class mypack.ShowBalance
BankCustomer bc = new BankCustomer(userid, username, bal
ance, level);
^
C:\jakarta-tomcat\webapps\Assignment1\WEB-INF\classes\mypack\ShowBalance.java:47
: cannot resolve symbol
symbol : class BankCustomer
location: class mypack.ShowBalance
BankCustomer bc = new BankCustomer(userid, username, bal
ance, level);
^
2 errors类A的代码:
package mypack;import java.io.*;
import java.sql.*;
import java.util.*;public class ShowBalance {
public ShowBalance(String UserName)
throws IOException{
try{ String clientName = UserName;
//connect to database
String dbUrl = "jdbc:mysql://localhost:3306/balancecontrol";
String dbUser = "Jay";
String dbPwd = "123456";
//load driver
Class.forName("com.mysql.jdbc.Driver");
//regesister driver
java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
Statement stmt = con.createStatement();
String sql = "select user_id, user_name, balance, level from user_balance where user_name = '" + clientName + "' ";
ResultSet rs = stmt.executeQuery(sql);
int userid = 1000;
String username = "New Customer";
float balance = 0;
int level = 3;
if(rs.next()){
userid = rs.getInt("user_id");
username = rs.getString("user_name");
balance = rs.getFloat("balance");
level = rs.getInt("level");
}
rs.close();
stmt.close();
con.close();
BankCustomer bc = new BankCustomer(userid, username, balance, level);
}
catch(Exception e){
throw new IOException(e.getMessage());
}
}
}类B的代码:
package mypack;public class BankCustomer{ private int userid = 1000;
private String username = "New Customer";
private float balance = 0;
private int level = 3;
public void Bankcustomer(int userid, String username, float balance, int level){
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}
public int getUserID(){
return userid;
} public String getUserName(){
return username;
} public float getBalance(){
return balance;
}
public int getLevel(){
return level;
}
}
在编译类A的时候出错,刚刚看JAVA三天,现在还有点搞不清晨面的关系,请大侠们帮忙看看。
编译类A时出错信息:
C:\Documents and Settings\Shaun>javac C:\jakarta-tomcat\webapps\Assignment1\WEB-
INF\classes\mypack\ShowBalance.java
C:\jakarta-tomcat\webapps\Assignment1\WEB-INF\classes\mypack\ShowBalance.java:47
: cannot resolve symbol
symbol : class BankCustomer
location: class mypack.ShowBalance
BankCustomer bc = new BankCustomer(userid, username, bal
ance, level);
^
C:\jakarta-tomcat\webapps\Assignment1\WEB-INF\classes\mypack\ShowBalance.java:47
: cannot resolve symbol
symbol : class BankCustomer
location: class mypack.ShowBalance
BankCustomer bc = new BankCustomer(userid, username, bal
ance, level);
^
2 errors类A的代码:
package mypack;import java.io.*;
import java.sql.*;
import java.util.*;public class ShowBalance {
public ShowBalance(String UserName)
throws IOException{
try{ String clientName = UserName;
//connect to database
String dbUrl = "jdbc:mysql://localhost:3306/balancecontrol";
String dbUser = "Jay";
String dbPwd = "123456";
//load driver
Class.forName("com.mysql.jdbc.Driver");
//regesister driver
java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
Statement stmt = con.createStatement();
String sql = "select user_id, user_name, balance, level from user_balance where user_name = '" + clientName + "' ";
ResultSet rs = stmt.executeQuery(sql);
int userid = 1000;
String username = "New Customer";
float balance = 0;
int level = 3;
if(rs.next()){
userid = rs.getInt("user_id");
username = rs.getString("user_name");
balance = rs.getFloat("balance");
level = rs.getInt("level");
}
rs.close();
stmt.close();
con.close();
BankCustomer bc = new BankCustomer(userid, username, balance, level);
}
catch(Exception e){
throw new IOException(e.getMessage());
}
}
}类B的代码:
package mypack;public class BankCustomer{ private int userid = 1000;
private String username = "New Customer";
private float balance = 0;
private int level = 3;
public void Bankcustomer(int userid, String username, float balance, int level){
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}
public int getUserID(){
return userid;
} public String getUserName(){
return username;
} public float getBalance(){
return balance;
}
public int getLevel(){
return level;
}
}
解决方案 »
- java socket 服务端程序怎么写并且能在web中来调用服务端的socket来发送和接收数据
- 请问我学习了JSP已经会了 servlet和 用javabean进行一些数据封装 请问我下一步能学习框架吗 ???
- 一个关于Action线程安全的问题,大侠帮我看看,定给分!
- 荤?郁闷几天了,高手救我啊!!sql查询问题!
- 初学struts,请教连接sql Server数据库的方法(越简单越好,呵呵)
- 能不能通过javascript实现,把表单的信息送出,然后刷新页面,而无需反馈!
- hql update多表多条件更新。
- 关于下载时出现的中文文件无法找到的问题
- 请问如何控制IE里的菜单和工具栏?
- Servlet 成员变量问题,望大神特来指教
- 100分求解一个javascript中传递参数时碰到有引号的String的问题
- 求 能验证 yyyy-MM-dd HH:mm:ss 格式的 正则表达式 ! 牛人请进 !
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}改成 public void Bankcustomer(int userid1, String username1, float balance1, int level1){
this.userid = userid1;
this.username = username1;
this.balance = balance1;
this.level = level1;
}注意形参名不要与本身变量名相同
应该是public Bankcustomer(int userid, String username, float balance, int level){
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}
BankCustomer bc = new BankCustomer(userid, username, balance, level);
INF\classes\mypack\BankCustomer.java
C:\jakarta-tomcat\webapps\Assignment1\WEB-INF\classes\mypack\BankCustomer.java:1
0: invalid method declaration; return type required
public Bankcustomer(int userid, String username, float balance, int leve
l){
^
1 error
改成:public void BankCustomer
private String username = "New Customer";
private float balance = 0;
private int level = 3;
public void Bankcustomer(int userid, String username, float balance, int level){
this.userid = userid;
this.username = username;
this.balance = balance;
this.level = level;
}
构造函数名应该和类名一致,java是区分大小写的哦!