I am getting a nut pointer exception when adding an element to the list.
Error is System.NullPointerException: Attempt to de-reference a null object on out.add(Time.newInstance(17,00,00,00));
public class BusScheduleCache
{ //Variable
private Cache.OrgPartition part;
//Constructor
public BusScheduleCache()
{
Cache.OrgPartition newobj = Cache.Org.getPartition('local.BusSchedule');
part = newobj;
}
//methods
public void putSchedule(String busLine, Time[] schedule)
{
part.put(busline, schedule);
}
public Time[] getSchedule (String busline)
{
Time[] out = new List<Time>();
out = (Time[]) part.get(busline);
if (out == null)
{
out.add(Time.newInstance(8, 00, 00, 00));
out.add(Time.newInstance(17,00,00,00));
}
return out;
}
}
The problem is that you are checking if the list out is null:
if (out == null) { }
Inside that condition you are then adding to a null list.
Also review these two lines:
Time[] out = new List<Time>();
out = (Time[]) part.get(busline);
First you instantiate the variable out with a new list, but then you assign null reference to it again.
It might be useful doing something like this:
Time[] out = part.containsKey(busline) ?
(Time[]) part.get(busline) : new List<Time>();
if (out.isEmpty())
{
out.add(Time.newInstance(8, 00, 00, 00));
out.add(Time.newInstance(17,00,00,00));
}
return out;
Related
I created a parser that reads files formatted in the following way:
version="v4.5.32"
name="Test File"
date="2513.04.02"
players=
{
{
first_name="John"
last_name="Smith"
country=12
id=0
}
{
first_name="Mario"
last_name="Rossi"
country=56
id=1
}
}
next_player_id=2
matches=
{
22 47 88 1045 1048 3511
}
settings=
{
match_prefix="game"
match_reward_scalar=1,55
match_sets_points=
{
0,5 0,75 1,0
}
next_event_id=56
next_event_fired=false
next_event_probability=0,33
}
...
Basically, those files contain a list of key/value pairs in which keys are always a string and values can be either a simple value (boolean, date, float, integer, string), a record (a sublist of key/value pairs like settings) or an array (composed by simple values like matches or records like players). In order to parse and handle those values I created 3 simple classes.
1) MyPair
public sealed class MyPair
{
public MyKey Key { get; }
public MyValue Value { get; }
public MyPair(MyKey key, MyValue value) { ... }
public override String ToString()
{
return String.Concat(Key, " = ", Value);
}
}
2) MyKey
public sealed class MyKey
{
public String Name { get; }
... // other properties set by checking the name in the constructor
public Key(String name) { ... }
public override String ToString()
{
return Name;
}
}
3) MyValue
public sealed class MyValue
{
private readonly dynamic m_UnderlyingValue;
private readonly MyValueCategory m_Category;
public dynamic UnderlyingValue
{
get { return m_UnderlyingValue; }
}
public Boolean Container
{
get { return ((m_Category == ValueCategory.Array) || (m_Category == ValueCategory.Record)); }
}
public MyValueCategory Category
{
get { return m_Category; }
}
public MyValue(DateTime underlyingValue)
{
if (underlyingValue == null)
throw new ArgumentNullException("underlyingValue");
m_UnderlyingValue = underlyingValue;
m_Category = MyValueCategory.DateTime;
}
public MyValue(Boolean underlyingValue) { ... }
public MyValue(Double underlyingValue) { ... }
public MyValue(Int64 underlyingValue) { ... }
public MyValue(MyPair[] underlyingValue) { ... }
public MyValue(MyValue[] underlyingValue) { ... }
public MyValue(String underlyingValue) { ... }
public override String ToString()
{
switch (m_Category)
{
case MyValueCategory.Array:
return String.Concat("Array[", m_UnderlyingValue.Length, "]");
case MyValueCategory.Boolean:
return String.Concat("Boolean[", (m_UnderlyingValue ? "true" : "false"), "]");
case MyValueCategory.DateTime:
return String.Concat("DateTime[", m_UnderlyingValue.ToString("yyyy.MM.dd", CultureInfo.InvariantCulture), "]");
case MyValueCategory.Float:
return String.Concat("Float[", m_UnderlyingValue.ToString("F3", CultureInfo.InvariantCulture), "]");
case MyValueCategory.Integer:
return String.Concat("Integer[", m_UnderlyingValue.ToString("F0", CultureInfo.InvariantCulture), "]");
case MyValueCategory.Record:
return String.Concat("Record[", m_UnderlyingValue.Length, "]");
default:
return String.Concat("Text[", m_UnderlyingValue, "]");
}
}
}
public enum MyValueCategory
{
Array,
Boolean,
DateTime,
Float,
Integer,
Record,
Text
}
The parsing process works like a charm and returns me a MyValue instance that works like a container / root node for everything I parsed.
I'm not using WPF forms, just plain Winforms. I would like to populate a TreeView control hierarchically with the parsed data and then make that data responsive to the changes made to the TreeView nodes. I really can't figure out how to bind data to the control itself and allow a mirrored manipulation.
Any suggestion please?
You can populate your TreeView recursively with this code:
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
MyValue root = new MyParser().Parse( "MyFilename.own" );
Populate( treeView1.Nodes, root.UnderlyingValue );
}
protected void Populate( TreeNodeCollection nodes, IList list )
{
if( list is MyPair[] )
{
foreach( MyPair pair in list )
{
TreeNode node = new TreeNode();
node.Text = pair.ToString();
node.Tag = pair;
nodes.Add( node );
if( pair.Value.Container )
Populate( node.Nodes, (IList)pair.Value.UnderlyingValue );
}
}
if( list is MyValue[] )
{
foreach( MyValue value in list )
{
TreeNode node = new TreeNode();
node.Text = value.ToString();
node.Tag = value;
nodes.Add( node );
if( value.Container )
Populate( node.Nodes, (IList)value.UnderlyingValue );
}
}
}
Result looks then like that:
As #Reza Aghaei already mentioned it is not possible to do this via data-binding. You have to maintain your lists manually after adding/removing a node. Setting node.Tag to the corresponding pair or value makes it easy for you to find and modify them.
In my programme I've a large array of strings(say 1600) which I want to show as a CheckBox list. The array is actually the location of all the songs in one's PC, and thus can gradually be bigger. I don't wanna use ListView<String> as the CheckBox list is more efficient and above all visually better for my purpose. I'm currently doing the below :
private void listAll() {
songs = MediaManager.getAllSongs();
VBox vb = new VBox();
vb.setSpacing(5);
vb.getStyleClass().add("background");
if (songs != null) {
Service s = new Service() {
#Override
protected Task createTask() {
Task t = new Task() {
#Override
protected Object call() throws Exception {
for (String song : songs) {
addSong(song, vb);
c++;
updateMessage(c+" songs");
}
return null;
}
};
t.messageProperty().addListener((obs,o,n)->{
count.setText(n);
});
return t;
}
};
s.start();
ScrollPane sp = new ScrollPane(vb);
getChildren().add(sp);
}
}
private void addSong(String n, Pane p) {
String toAdd = "";
Media m = new Media(Paths.get(n).toUri().toString());
if (m.getMetadata().get("title") == null || !(m.getMetadata().get("title").equals(""))) {
toAdd = m.getSource().split("/")[m.getSource().split("/").length - 1].replace("%20", " ").replace(".mp3", "");
} else {
toAdd = ((String) m.getMetadata().get("title"));
}
SongBox s = new SongBox(toAdd);
s.setUserData(n);
p.getChildren().add(s);
}
class SongBox extends CheckBox {
public SongBox(String t) {
this();
setText(t);
}
public SongBox() {
super();
setOnAction((ActionEvent evt) -> {
if (isSelected()) {
if (!playNow.isVisible()) {
playNow.setVisible(true);
}
path = (String) getUserData();
selected.add((String) getUserData());
} else {
selected.remove((String) getUserData());
if (selected.size() == 0) {
playNow.setVisible(false);
}
}
});
}
}
First of all, that is not showing the complete array. Whenever I'm going back and returning to it, the number of songs get changed. Secondly, the whole UI is getting sluggish(sometimes also hanging my PC). Moreover, I can't cancel the Service when I've gone to the previous window, as it's always returning false. Anyone have a better approach?
I have this Java class where I am writing the code for applying the overrides. I want to know if using ENUM is appropriate or if I need to use the switch case, how can I use it? Also, I have the for loop that I need to use as a common block of code for each override type. Apart from that, I do have few separate fields that I need to code for each override type.
public class EWFMService
{
private WorkbrainSystemAccessService wsa = new WorkbrainSystemAccessService();
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EWFMService.class);
private final static String ovrCalcGrp = "ovrCalcGrp";
private DBConnection conn = null;
private int empId;
private Date ovrDate;
private String ovrTime;
private String ovrAction;
public List<EWFMServiceData> getProcessEWFMOverrides(String userName, String password, List<EWFMServiceInputData> inputData)
throws WSApplicationException{
logger.debug("EWFM Service");
wsa.logOn(userName, password);
List<EWFMServiceData> returnList = new ArrayList<EWFMServiceData> ();
logger.debug("userName = " + userName);
DBConnection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
conn = new DBConnection(ConnectionManager.getConnection());
for (int i = 0; i < inputData.size(); i++)
{
Here I want to retrieve the emp_id from the database, store the value in a variable and be able to use the variable in the rest of my program. How do I do it? To retrieve the emp_id, I am using the following query.
conn = new DBConnection(ConnectionManager.getConnection());
String sql = "SELECT EMP_ID FROM EMPLOYEE_HISTORY"
+ " WHERE EMP_VAL2 = **This is where I want to use the variable in which the values of emp_id will be stored. There can be more than 100 emp_ids**"
+ " AND SYSDATE BETWEEN EMPHIST_START_DATE AND EMPHIST_END_DATE";
EWFMServiceInputData inData = (EWFMServiceInputData) inputData.get(i);
OverrideType ot = OverrideType.getOverrideType(inData.getRecordType());
logger.debug("override type = " + ot.toString());
logger.debug("inputData ["+i+"] = " + inData.toString());
OverrideAccess oa = new OverrideAccess(conn);
OverrideData ovr = new OverrideData();
ovr.setOvrUdf4(inData.getReferenceId().toString());
if (ovrAction.equals("APPLY")) {
ovr.setOvrStatus(OverrideData.PENDING);
Here I want to determine the Action. If it is Apply, then I need to find out the recordType. So basically branch it out for each recordType using if else statements or enum as I believe switch doesn't support Java 1.5 which is what I am using. Then for each recordType, I branch out and write the appropriate code corresponding to that recordType. If Action is CANCEL, then I just write the following code.
} else if (ovrAction.equals("CANCEL")) {
String sql = "SELECT * FROM OVERRIDE"
+ " WHERE OVR_UDF4 = ?"
+ " AND OVRTYP_ID = ?";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()); {
ovr.assignByName(rs);
ovr.setUpdated(false);
ovr.setRetrieved(true);
ovr.setOvrStatus(OverrideData.CANCEL);
oa.save(ovr);
}
}
ovr.setEmpId(empId);
String strOvrDate = inData.getOvrStartDate();
ovr.setOvrStartDate(DateHelper.parseDate(strOvrDate, "MM/dd/yyyy"));
if (ovrStartTime != null) {
ovr.setOvrStartTime(ovrTime);
}
Object ovrEndDate;
if (ovrEndDate != null) {
ovr.setOvrEndDate(ovrDate);
}
Object ovrEndTime;
if (ovrEndTime!= null) {
ovr.setOvrEndTime(ovrTime);
}
ovr.setOvrComment(inData.getOvrComments());
ovr.setWbuName(inData.getWbuName());
ovr.setWbuNameActual(inData.getWbuNameActual());
ovr.setOvrNewValue("VAC");
ovr.setOvrCreateDate(new Date());
ovr.setOvrtypId(103);
oa.insert(ovr);
RuleEngine.runCalcGroup(conn,
empId,
ovrDate,
ovrDate);
//COMMON BLOCK ENDS HERE
EWFMServiceData outData = new EWFMServiceData();
outData.setReferenceId(inData.getReferenceId());
String [] status = {"SUCCESS", "ERROR", "LOCKED", "EXCEPTION"};
Random ran = new Random();
String gen = status[ran.nextInt(status.length)];
logger.debug("Status is" + status );
outData.setStatus(gen);
if (gen.equals("SUCCESS")){
outData.setErrorDetails("");
} else if (gen.equals("ERROR")) {
outData.setErrorDetails("Usage of time code VAC is not allowed; balance is insufficient." + " error");
} else if (gen.equals("LOCKED")) {
outData.setErrorDetails("Timesheet cannot be edited because it is locked for payroll close." + "locked");
} else if (gen.equals("EXCEPTION")) {
outData.setErrorDetails("{ML}QR_INCORRECT_CONDITION_PARAMETER{/ML}Error in condition AWA Is Self Override Condition: java.lang.NullPointerException{ARGS}AWA Is Self Override Conditionjava.lang.NullPointerException{/ARGS" + "exception");
}
returnList.add(outData);
}
}catch (Exception e){
logger.error("Error occured",e);
throw new WSApplicationException("Error retrieved",e);
}finally{
SQLUtil.cleanUp(conn, ps, rs);
}
wsa.logOff();
logger.debug("inputData+ ");
return returnList;
}
// I need to know if writing enum is okay or can I just write a switch case above in the for loop and branch each override type and declare their individual variables there? What's the best way? Can someone help me with the code?
public enum OverrideType {
WORKDETAIL,
WORKPREMIUM,
EMPLOYEESCHEDULE,
EMPLOYEE;
public static OverrideType getOverrideType(String recordType) {
if(recordType == null) {
throw new IllegalArgumentException("Record Type cannot be null");
}
if(recordType.equals("Work Detail")) {
return WORKDETAIL;
} else if (recordType.equals("Work Premium")) {
return WORKPREMIUM;
} else if (recordType.equals("Schedule")) {
return EMPLOYEESCHEDULE;
} else if (recordType.equals("Shift Pattern")) {
return EMPLOYEE;
} else {
throw new IllegalArgumentException("Record Type cannot be" + recordType);
}
}
}
}
THE OTHER FIELDS I NEED TO INCLUDE ARE AS FOLLOWS:
FOR WORKDETAIL, I NEED TO USE TIMECODE OF FORMAT THAT IS SENT BY THE CLIENT.
FOR WORK PREMIUM, I NEED TO USE TIMECODE OF FORMAT THAT IS SENT BY THE CLIENT AND ANOTHER FIELD IS MINUTES THAT GIVES THE NUMBER OF MINUTES WHICH IS ALSO SENT BY THE CLIENT.
Generally, using enums is appropriate, especially if you have a defined set of possible types.
You can also add behavior to the enums, which could make your enum a little bit more sophisticated:
public enum OverrideType {
WORKDETAIL("Work Detail"),
WORKPREMIUM("Work Premium"),
EMPLOYEESCHEDULE("Schedule"),
EMPLOYEE("Shift Pattern");
private String identifier;
private OverrideType(String identifier){
this.identifier = identifier;
}
public static OverrideType getOverrideType(String recordType) {
if(recordType == null) {
throw new IllegalArgumentException("Record Type cannot be null");
}
for (OverrideType ot : OverrideType.values()) {
if (recordType.equals(ot.identifier)) {
return ot;
}
}
return null;
}
}
The following example shows how to use an interface in enums or an abstract method definition:
public enum OverrideType implements OverrideTypeIF {
WORKDETAIL("Work Detail") {
public int getKey() {
return 0;
}
},
WORKPREMIUM("Work Premium") {
public int getKey() {
return 0;
}
},
EMPLOYEESCHEDULE("Schedule") {
public int getKey() {
return 0;
}
},
EMPLOYEE("Shift Pattern") {
public int getKey() {
return 0;
}
public void myInterfaceMethod() {
// do type specific behavior
}
};
private String identifier;
private OverrideType(String identifier){
this.identifier = identifier;
}
public abstract int getKey();
public void myInterfaceMethod() {
// do default behavior
}
public static OverrideType getOverrideType(String recordType) {
if(recordType == null) {
throw new IllegalArgumentException("Record Type cannot be null");
}
for (OverrideType ot : OverrideType.values()) {
if (recordType.equals(ot.identifier)) {
return ot;
}
}
return null;
}
}
public interface OverrideTypeIF {
void myInterfaceMethod();
}
I finally understood the various possibilities of Comparable from java.util.Collections;
I can order an object, for example "Beer" with attributes float content, String name and String origin in any order that I want, combining them how I want.
Now the question:
I have the following classes (code provided last):
Building()
Address();
Building can be one of three types, for example Dwelling, House, Bungalow.
Now, task is "to sort all buildings, first by the city (ascending), second by the street (ascending) and then by the street number (ascending).
Normally I would simply sort the list first by city, then by street and then by number. Of course after the first sort its solution would get mixed up by the following sorts.
Thats why I searched the net and found Comparable.
Thing is: It did work with the beer example, but does not with the address. Cause it is implemented as an ArrayList, and as I found out, it just works for Arrays.
But even if it did, the Addresses themselves are not an Array, but part of the Object Building.
So how on god's earth is one supposed to solved this?
I think I spent more than 8 hours with this cr*p, and the students are supposed to solve similiar issues within 2 - 3 hours.
Any suggestions are appreciated.
Thanks,
Neo
import java.util.List;
public abstract class Building {
private Address address;
private List<Owner> owners;
public abstract double getCostRate(double costs);
public void setAddress(Address address) {
this.address = address;
}
public Address getAddress() {
return address;
}
public List<Owner> getOwners() {
return owners;
}
}
Class Address:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import de.uni_mannheim.informatik.swt.pm.extended.ComparatorCityStreetNumber;
public class Address implements Comparable<Address> {
private String street;
private int houseNr;
private int zip;
private String city;
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public int getZip() {
return zip;
}
public void setZip(int zip) {
this.zip = zip;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public void setHouseNr(int houseNr) {
this.houseNr = houseNr;
}
public int getHouseNr() {
return houseNr;
}
/**
* eclipse is able to generate the equals method automatically ;)
*/
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (city == null) {
if (other.city != null)
return false;
} else if (!city.equals(other.city))
return false;
if (country == null) {
if (other.country != null)
return false;
} else if (!country.equals(other.country))
return false;
if (houseNr != other.houseNr)
return false;
if (street == null) {
if (other.street != null)
return false;
} else if (!street.equals(other.street))
return false;
if (zip != other.zip)
return false;
return true;
}
Comparator:
public class ComparatorCityStreetNumber implements Comparator<Address> {
public int compare(Address a1, Address a2) {
if (a1.getCity().compareTo(a2.getCity()) == 0) {
if (a1.getStreet().compareTo(a2.getStreet()) == 0) {
if (a1.getHouseNr() > a2.getHouseNr()) {
return -1;
} else {
return a1.getStreet().compareTo(a2.getStreet());
}
} else if (a1.getCity().compareTo(a2.getCity()) > 0) {
return -1;
} else {
return 1;
}
}
return 0;
}
}
It looks like your Building is an abstract class, which gives you a hint that you must extend it.
Given that this is an assignment, I'm not going to do it for you. Instead, I will give you some pointers :-)
Create a Property object which extends Building, and implement the getCostRate method which returns zero for now. Either that, or make Building concrete.. My guess is that subclasses of Building are yet to come, so if that's the case, scratch that idea.
Now create a PropertyComparator implementation of the Comparator object.
Now, from the perspective of being able to determine your sort criteria, you should be able to write the simple logic to compare one Property with another Property, and their corresponding Addresses - if you want to go for gold, create an AddressComparator too - and make your BuildingComparator call the AddressComparator to compare the addresses.
Finally, if you have a collection of Property objects, put them into a TreeSet, but construct the TreeSet with your PropertyComparator.
Once it's in the TreeSet, it will be ordered according to your implementation.
Good luck!
I found my mistake, it was in the last equasion. IF must not be this.getCity().compareTo(address.getCity()) = 0 but correctly has to be this.getCity().compareTo(address.getCity()) > 0
So, the whole code to sort after my criteria looks like this:
public int compareTo(Address address) {
if (this.getCity().compareTo(address.getCity()) == 0) {
if (this.getStreet().compareTo(address.getStreet()) == 0) {
if (this.getHouseNr() > address.getHouseNr()) {
return 1;
} else {
return -1;
} // end house number
} else {
return this.getStreet().compareTo(address.getStreet());
} //end street
} else if (this.getCity().compareTo(address.getCity()) > 0) {
return 1;
} else {
return -1;
} //end city
}
You just need to implement compareTo(...) method and there is where you should put the Address comparison logic, that will be used when you call Collections.sort(...) method for a List<Address>object.
Example:
List<Address> l = new ArrayList<Address>();
// ... fill values in the list
Collections.sort(l);
This will use the logic from your compareTo(...) method in Address class. For example:
int compareTo(Address o) {
return o.getCity().compareTo(this.getCity());
}
So this would be using the String implementation of compareTo(...) method for sorting the Addresses by city. And in this way you don't need to use the ComparatorCityStreetNumber class nor any other Comparator class.
For more information:
http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)
EDIT:
If your compareTo(...) method doesn't work you can always place this logic in the compare(Address a1, Address a2) method in your ComparatorCityStreetNumber class.
Then you don't need to implement Comparable anymore in your Address class nor implement compareTo(...) method there.
And then your sort call would be:
List<Address> l = new ArrayList<Address>();
// fill in the list with addresses
ComparatorCityStreetNumber c = new ComparatorCityStreetNumber();
Collections.sort(l, c);
So please try this and edit your question with your new output if you have other problems there.
For more information: http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html#compare(T, T)
I am trying to get my hands on WPF, and I have encountered a small problem when updating, mainly that I am getting the old data displayed while the new data is correctly updated in the XML file. I have implemented INotifyPropertyChanged as follows :-
public class Products : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _prodId;
public string ProdID
{
get { return _prodId; }
set
{
_prodId = value;
OnPropertyChanged("ProdID");
}
}
private string _prodName;
public string ProdName
{
get { return _prodName; }
set
{
_prodName = value;
OnPropertyChanged("ProdName");
}
}
private string _prodPrice;
public string ProdPrice
{
get { return _prodPrice; }
set
{
_prodPrice = value;
OnPropertyChanged("ProdPrice");
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
and then the update is as follows :-
foreach (XmlNode node in nodeList)
{
if (nodeList[i].ChildNodes[0].InnerText == strID)
{
Products products = new Products();
products.ProdName = strName;
products.ProdPrice = strPrice;
nodeList[i].ChildNodes[1].InnerText = strName;
nodeList[i].ChildNodes[2].InnerText = strPrice;
break;
}
i++;
}
The XML is being saved correctly with the new ProdName and Price, however when I display the listView after the update, i am still getting the wrong values.
I am binding the Products like this:-
public static List<Products> LoadProduct()
{
string fileName = "Products.xml";
List<Products> ListProdRecords = new List<Products>();
// Execute the query using the LINQ to XML
var prods = from p in XElement.Load(fileName).Elements("Product") select p;
foreach (var product in prods)
{
Products lProduct = new Products
{
ProdID = product.Element("ProductId").Value,
ProdName = product.Element("ProductName").Value,
ProdPrice = product.Element("Price").Value
};
ListProdRecords.Add(lProduct);
}
return ListProdRecords.ToList();
}
here is the binding code :-
private void LoadProducts()
{
List<Products> productList = new List<Products>();
productList = ProductDAL.LoadProduct();
listView1.DataContext = productList;
}
public static void UpdateProduct(string strID, string strName, string strPrice)
{
string fileName = "Products.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
XmlNodeList nodeList = xmlDoc.SelectNodes("/Products/Product");
int i = 0;
foreach (XmlNode node in nodeList)
{
if (nodeList[i].ChildNodes[0].InnerText == strID)
{
Products products = new Products();
products.ProdName = strName;
products.ProdPrice = strPrice;
nodeList[i].ChildNodes[1].InnerText = strName;
nodeList[i].ChildNodes[2].InnerText = strPrice;
break;
}
i++;
}
Any help on what's wrong?
Thanks for your help and time
I don't really see, what the newly created products in your loop have to do with a listView. You don't add them to a list or add them to the listView in another way.
Or in other words: The creation of those instances inside your loop is completely useless and will be removed by the optimizer.
You need to update the instances of the Products class that are in the list you bound to the listView.