使用程序运行后编译错误

时间:2013-01-11 05:21:48

标签: java compiler-errors

主程序

package esss;
// Add
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import esss.DBI;
import esss.Shared;
import esss.Control;



public class deduction extends esss.Control {
protected DBI dbi;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
  HttpSession session = request.getSession();
  esss.Shared bean = (esss.Shared)session.getAttribute("shared");

  //String[] checked = request.getParameter("deduction");// needs parameter
  String type = request.getParameter("deduction");// needs parameter
  String amount = request.getParameter("amount");

  addDeduction(bean, type, amount);
  gotoPage("/mainPage.jsp", request, response);
}

public void addDeduction(esss.Shared bean,String type, String amount) throws ServletException{
  try {
    dbi = new esss.DBI();
    if(dbi.connect()) {
      String payment ="";
      if(type.equals("Parking Lot A")) {
        payment="10";
      }
      else if(type.equals("Parking Lot B")) {
        payment="5";
      }
      else if(type.equals("Extra Life Insurance(Age<35, 50,000)")) {
        payment="5";
      }
      else if(type.equals("Extra Life Insurance(Age 35-55, 25,000)")) {
        payment="17";
      }
      else if(type.equals("Extra Life Insurance(Age>55, 10,000)")) {
        payment="35";
      }

      if(!(type.equals("none"))) {
        String empId= bean.getEmpId();
        String dedDate = bean.getCurrentDate();
        //String dedId = bean.getdedId();
        //String dedname = bean.getdedName();
        //String dedAmount = bean.getAmount();
        dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
        bean.setMessage("Deduction Added");
      }
      else {
        bean.setMessage("Please make sure you perfrom deduction");
      }
      dbi.close();
    }
    }catch(Exception e) {
      e.printStackTrace();
      bean.setMessage("Exception caught : " + e);
      bean.setError("The database could not be connected");
    }
  }
}

编译器错误

compile:
[javac] Compiling 22 source files to /home/student/mcintron/cps4931/maricarmen/build/WEB-INF/classes
[javac] /home/student/mcintron/cps4931/maricarmen/src/deduction.java:71: cannot find symbol
[javac] symbol  : variable dedId
[javac] location: class esss.deduction
[javac]                     dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
[javac]                                               ^
[javac] /home/student/mcintron/cps4931/maricarmen/src/deduction.java:71: cannot find symbol
[javac] symbol  : variable dedName
[javac] location: class esss.deduction
[javac]                     dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
[javac]                                                      ^
[javac] 2 errors

BUILD FAILED

这是主要代码,当我使用编译器进行编译时,它给了我错误。我不明白为什么会出现这个错误?

2 个答案:

答案 0 :(得分:0)

您没有声明这两个变量,对吗?

在行中:

 dbi.updateDeduction(empId,dedId, dedName, type,dedDate);

dedIddedName

所以你需要取消注释它们......仔细看,就在上面。我猜可能还有另外一个问题。一般来说,如果它说它找不到XYZ就意味着它甚至没有声明

答案 1 :(得分:0)

dedId未声明,我可以在评论中找到以下行,如果您可以取消注释您的代码或下面可能编译的行。

  //String dedId = bean.getdedId();
  //String dedname = bean.getdedName();

替换这个

//String dedId = bean.getdedId();
//String dedname = bean.getdedName();

这一个

 String dedId = bean.getdedId();
 String dedname = bean.getdedName();