The method getItemNo() is undefined for the type Item怎么解决
public class ItemDao4OracleImpl implements ItemDao { public void addItem(Connection conn, Item item) {
    String sql="insert into t_items(item_no,itme_category_id,item_unit_id,item_name,spec,pattern)";
    sql+=" values(?,?,?,?,?,?)";
    PreparedStatement pstmt= null;
 try{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, item.getItemNo());
pstmt.setString(2, item.getItemName());
pstmt.setString(3, item.getSpec());
pstmt.setString(4, item.getPattern());
pstmt.setString(5, item.getItemCategory().getId());
pstmt.setString(6, item.getItemUnit().getId());
为什么显示:The method getItemNo() is undefined for the type Item?
Item 类里我已经定义了:
private String itemNo;
private String itemName;
private String spec;
private String pttern;
private ItemCategory itemCategory;
private ItemUnit itemUnit;

解决方案 »

  1.   

    说的很明白了Item类中没有定义
    getItemNo()方法,虽然类中有itemNo字段
    你却没有编写getItemNo()方法
      

  2.   

    我定义了get和set方法了,pstmt.setString(1, item.getItemNo());我这样调用是说没有定义了!!! 求解答!
      

  3.   

     我定义了set和get方法了?还是不行了?
      

  4.   

     恩是啊提示:The method getItemNo() is undefined for the type Item
      

  5.   

    文本编辑器里面敲的代码吧。
    名字坑爹是敲错了,看看是不是大小写原因,或者干脆把item里的方法复制过来试试吧。
      

  6.   

    package com.bjpowernode.drp.basedata.domain;import com.bjpowernode.drp.util.datadict.domain.ItemCategory;
    import com.bjpowernode.drp.util.datadict.domain.ItemUnit;/**
     * 物料实体类
     * @author lenovo
     *
     */
    public class Item {
    private String itemNo;
    private String itemName;
    private String spec;
    private String pttern;
    //g关联物料类别ItemCategory
    private ItemCategory itemCategory;
    private ItemUnit itemUnit;
    public String getItemNo() {
    return itemNo;
    }
    public void setItemNo(String itemNo) {
    this.itemNo = itemNo;
    }
    public String getItemName() {
    return itemName;
    }
    public void setItemName(String itemName) {
    this.itemName = itemName;
    }
    public String getSpec() {
    return spec;
    }
    public void setSpec(String spec) {
    this.spec = spec;
    }
    public String getPttern() {
    return pttern;
    }
    public void setPttern(String pttern) {
    this.pttern = pttern;
    }
    public ItemCategory getItemCategory() {
    return itemCategory;
    }
    public void setItemCategory(ItemCategory itemCategory) {
    this.itemCategory = itemCategory;
    }
    public ItemUnit getItemUnit() {
    return itemUnit;
    }
    public void setItemUnit(ItemUnit itemUnit) {
    this.itemUnit = itemUnit;
    }
    }
      

  7.   

    package com.bjpowernode.drp.basedata.domain;import com.bjpowernode.drp.util.datadict.domain.ItemCategory;
    import com.bjpowernode.drp.util.datadict.domain.ItemUnit;/**
     * 物料实体类
     * @author lenovo
     *
     */
    public class Item {
    private String itemNo;
    private String itemName;
    private String spec;
    private String pttern;
    //g关联物料类别ItemCategory
    private ItemCategory itemCategory;
    private ItemUnit itemUnit;
    public String getItemNo() {
    return itemNo;
    }
    public void setItemNo(String itemNo) {
    this.itemNo = itemNo;
    }
    public String getItemName() {
    return itemName;
    }
    public void setItemName(String itemName) {
    this.itemName = itemName;
    }
    public String getSpec() {
    return spec;
    }
    public void setSpec(String spec) {
    this.spec = spec;
    }
    public String getPttern() {
    return pttern;
    }
    public void setPttern(String pttern) {
    this.pttern = pttern;
    }
    public ItemCategory getItemCategory() {
    return itemCategory;
    }
    public void setItemCategory(ItemCategory itemCategory) {
    this.itemCategory = itemCategory;
    }
    public ItemUnit getItemUnit() {
    return itemUnit;
    }
    public void setItemUnit(ItemUnit itemUnit) {
    this.itemUnit = itemUnit;
    }
    }

    -----------------------------------------------------------------------------------------package com.bjpowernode.drp.basedata.dao;import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;import com.bjpowernode.drp.util.ApplicationException;
    import com.bjpowernode.drp.util.DbUtil;
    import com.bjpowernode.drp.util.PageModel;
    import com.sun.mail.imap.protocol.Item;public class ItemDao4OracleImpl implements ItemDao { public void addItem(Connection conn, Item item) {
        String sql="insert into t_items(item_no,itme_category_id,item_unit_id,item_name,spec,pattern)";
        sql+=" values(?,?,?,?,?,?)";
        PreparedStatement pstmt= null;
     try{
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, item.getItemNo());
    pstmt.setString(2, item.getItemName());
    pstmt.setString(3, item.getSpec());
    pstmt.setString(4, item.getPattern());
    pstmt.setString(5, item.getItemCategory().getId());
    pstmt.setString(6, item.getItemUnit().getId());
    pstmt.executeUpdate();
     }catch(SQLException e){
     e.printStackTrace();
     throw new ApplicationException("添加物料失败!");
     }finally{
    DbUtil.close(pstmt);
     }
     
    } public void delItem(Connection conn, String[] itemNos) {
    // TODO Auto-generated method stub } public Item findItemById(Connection conn, String itemNo) {
    // TODO Auto-generated method stub
    return null;
    } public PageModel findItemList(Connection conn,int pageNo, int pageSize, String condation) {
    // TODO Auto-generated method stub
    return null;
    } public void modifyItem(Connection conn, Item item) {
    // TODO Auto-generated method stub }}
      

  8.   

    import com.sun.mail.imap.protocol.Item;!!!!!!