我是Java的新手,很难理解如何访问方法并将变量设置为我的Bean类中的特定值。我正在创建Bean类的新实例,并希望将变量设置为特定值。我还想将这些全部存储在List中。这是我的代码: 公共类ReportBean { //实例变量
private String inventoryFulfillmentSpecialist;
private String inventoryFulfillmentManager;
private String poNumber;
private String poReferenceNumber;
private String shipToLoc;
private String poStatus;
private String importStatus;
private String orderType;
private String item;
private String mismatchFields;
private String tValue;
private String hValue;
/**
* Getter method for variable 'inventoryFulfillmentSpecialist'.
* @return String
*/
public String getInventoryFulfillmentManager() {
return inventoryFulfillmentManager;
}
/**
* Getter method for variable 'inventoryFulfillmentSpecialist'.
* @return String
*/
public String getInventoryFulfillmentSpecialist() {
return inventoryFulfillmentSpecialist;
}
/**
* Getter method for variable 'poNumber'.
* @return String
*/
public String getPoNumber() {
return poNumber;
}
/**
* Getter method for variable 'poReferenceNumber'.
* @return String
*/
public String getPoReferenceNumber() {
return poReferenceNumber;
}
/**
* Getter method for variable 'shipToLoc'.
* @return String
*/
public String getShipToLoc() {
return shipToLoc;
}
/**
* Getter method for variable 'poStatus'.
* @return String
*/
public String getPoStatus() {
return poStatus;
}
/**
* Getter method for variable 'importStatus'.
* @return String
*/
public String getImportStatus() {
return importStatus;
}
/**
* Getter method for variable 'orderType'.
* @return String
*/
public String getOrderType() {
return orderType;
}
/**
* Getter method for variable 'item'.
* @return String
*/
public String getItem() {
return item;
}
/**
* Getter method for variable 'tssVsPoMisMatchFields'.
* @return String
*/
public String getTssVsPODirectMisMatchFields() {
return tssVsPODirectMisMatchFields;
}
/**
* Getter method for variable 'tradeStoneValue'.
* @return String
*/
public String getTradeStoneValue() {
return tradeStoneValue;
}
/**
* Getter method for variable 'hostValue'.
* @return String
*/
public String getHostValue() {
return hostValue;
}
/**
* Setter method for variable 'inventoryFullfilmentManager'.
* @param inventoryFulfillmentManager String
*/
public void setInventoryFulfillmentManager(String inventoryFulfillmentManager) {
this.inventoryFulfillmentManager = inventoryFulfillmentManager;
}
/**
* Setter method for variable 'inventoryFulfillmentSpecialist'.
* @param inventoryFulfillmentSpecialist String
*/
public void setInventoryFulfillmentSpecialist(
String inventoryFulfillmentSpecialist) {
this.inventoryFulfillmentSpecialist = inventoryFulfillmentSpecialist;
}
/**
* Setter method for variable 'poNumber'.
* @param poNumber String
*/
public void setPoNumber(String poNumber) {
this.poNumber = poNumber;
}
/**
* Setter method for variable 'poReferenceNumber'.
* @param poReferenceNumber String
*/
public void setPoReferenceNumber(String poReferenceNumber) {
this.poReferenceNumber = poReferenceNumber;
}
/**
* Setter method for variable 'shipToLoc'.
* @param shipToLoc String
*/
public void setShipToLoc(String shipToLoc) {
this.shipToLoc = shipToLoc;
}
/**
* Setter method for variable 'poStatus'.
* @param poStatus String
*/
public void setPoStatus(String poStatus) {
this.poStatus = poStatus;
}
/**
* Setter method for variable 'importStatus'.
* @param importStatus String
*/
public void setImportStatus(String importStatus) {
this.importStatus = importStatus;
}
/**
* Setter method for variable 'orderType'.
* @param orderType String
*/
public void setOrderType(String orderType) {
this.orderType = orderType;
}
/**
* Setter method for variable 'item'.
* @param item String
*/
public void setItem(String item) {
this.item = item;
}
/**
* Setter method for variable 'tssVsPODirectMisMatchFields'.
* @param tssVsPODirectMisMatchFields String
*/
public void setTssVsPODirectMisMatchFields(String tssVsPODirectMisMatchFields) {
this.tssVsPODirectMisMatchFields = tssVsPODirectMisMatchFields;
}
/**
* Setter method for variable 'tradeStoneValue'.
* @param tradeStoneValue String
*/
public void setTradeStoneValue(String tradeStoneValue) {
this.tradeStoneValue = tradeStoneValue;
}
/**
* Setter method for variable 'hostValue'.
* @param hostValue String
*/
public void setHostValue(String hostValue) {
this.hostValue = hostValue;
}
List<ReportBean> reportData = new ArrayList<ReportBean>();
ReportBean bean1 = new ReportBean();
ReportBean bean2 = new ReportBean();
ReportBean bean3 = new ReportBean();
bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700");
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("ReportBean: ");
sb.append("inventoryFulfillmentManager = " + getInventoryFulfillmentManager() + " ");
sb.append("inventoryFulfillmentSpecialist = " + getInventoryFulfillmentSpecialist() + " ");
sb.append("poNumber = " + getPoNumber() + " ");
sb.append("poReferenceNumber = " + getPoReferenceNumber() + " ");
sb.append("shipToLoc = " + getShipToLoc() + " ");
sb.append("poStatus = " + getPoStatus() + " ");
sb.append("importStatus = " + getImportStatus() + " ");
sb.append("orderType = + " + getOrderType() + " ");
sb.append("item = " + getItem() + " ");
sb.append("tssVsPODirectMisMatchFields = " + getTssVsPODirectMisMatchFields() + " ");
sb.append("tradeStoneValue = " + getTradeStoneValue() + " ");
sb.append("hostValue = " + getHostValue() + " ");
return sb.toString();
}
}
我得到错误,当我试图说bean1.setxxxx时,我得到了红色的波浪线,它说“令牌上的语法错误,错位的构造”。如果有人能提供帮助,我将不胜感激,谢谢。
答案 0 :(得分:1)
bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700");
这部分代码只是浮动在你的类中。这是一个结构化的编程事物。在Java中,所有代码都必须位于方法或函数中。
你必须使用静态main方法来封装它:
public static void main(String[] args) {
//yourcode here
}
答案 1 :(得分:0)
import java.util.ArrayList;
class ReportBean {
private String InventoryFulfillmentManager;
private String InventoryFulfillmentSpecialist;
private String PoNumber;
private String PoReferenceNumber;
// Default constructor
public ReportBean() {}
public void setInventoryFulfillmentManager(String value) {
this.InventoryFulfillmentManager = value;
}
public void setInventoryFulfillmentSpecialist(String value) {
this.InventoryFulfillmentSpecialist = value;
}
public void setPoNumber(String value) {
this.PoNumber = value;
}
public void setPoReferenceNumber(String value) {
this.PoReferenceNumber = value;
}
}
public class Main {
public static void main(String[] args) {
ArrayList<ReportBean> list = new ArrayList<>();
for(int i = 0; i < 3; i++) {
list.add(new ReportBean());
list.get(i).setInventoryFulfillmentManager("Jackie Huffman");
list.get(i).setInventoryFulfillmentSpecialist("Phillip Smith");
list.get(i).setPoNumber("348794798");
list.get(i).setPoReferenceNumber("140629700");
}
}
}