NsMutableArray null value - nsmutablearray

I have a situation here. I have a UITableviewController with textfields in it in the cell. Each cellthas a textfield in it. The user enters the value in the textfields and i am saving the textfield data in to an NSMutableArray. But if the user doesnot enter a single field then my array gives the error
"CoreAnimation: ignoring exception: * -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 2". NSmutableArray cannot have a null value. How will i handle this situation. Any help is appreciated.
Thanks

A couple of quick solutions: I'm assuming that you must have a value in the array at the index that corresponds to the row, so what to put in? Stuff an [NSNull null] object in there, or simply an empty string.
if (!txtField.text) // if the textfield's text is null
{
[myMutableArray addObject:[NSNull null]];
}
One issue about this is that when reading your array, you cannot assume that the array holds a string: you must check it for [NSNull null] before setting your text.
Another solution to the issue would be to simply create an NSMutableDictionary to hold the values you wish to store, the key would be the NSIndexPath and the value would be the value you are storing. If the value is null, don't store anything at all. This way you would have no need to store null values.

Related

HashMap value (object) incorrectly overridden with incorrect value

I am iterating over a hashmap that is made of string keys and has objects as values and I am setting the attributes of the objects. The value of my hashmap is an object which has other objects as attributes. The problem is that once I set the value for the first object with key "1-1", in the second iteration when I want to set the value for my second key"2-1", the value corresponding to the first entry which was assigned right before ends up overridden with the value of the second entry, in other words, the attribute value of the first entry ends up overridden with the attribute value corresponding to the second entry. More specifically for key "1-1", in the first iteration of my hashmap, when I print methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold(), I get the value "T", then as soon as I move to the second key with value "2-1", I end up with a different value when I reprint methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold(), namely I end up with "N", while it should be "T" in reality, the "N" I am getting actually coresponds to the value of methodtraceHashMap2.get("2-1").Method.Owner.getDeveloperGold() which was set for the second entry of my hashmap which has the key "2-1"
for(MethodTrace MethodTrace: methodtraceHashMap2.values()) {
String reqClass=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.Owner.ID;
MethodTrace.Method.Owner.DeveloperGold=classTraceHashMap.get(reqClass).DeveloperGold;
System.out.println("yes");
}
System.out.println(methodtraceHashMap2.get("1-1").Method.Owner.getDeveloperGold());
Here is the snippet that populates the map but the problem arises in the previous snippet when I populate the attribute MethodTrace.Method.Owner.DeveloperGold of the MethodTrace, I do not believe that the problem is linked to the snippet below
ResultSet myresults = st.executeQuery("SELECT traces.* from traces");
while (myresults.next()) {
MethodTrace MethodTrace = new MethodTrace();
Method method= new Method();
Requirement requirement= new Requirement();
requirement=RequirementHashMap.get(myresults.getString("requirementid"));
method = MethodHashMap.get(myresults.getString("methodid"));
MethodTrace.setMethod(method);
MethodTrace.setRequirement(requirement);
//checking whether the method is present in the superclasses
MethodTrace.setGold(myresults.getString("goldfinal"));
String reqMethod=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.ID;
String reqClass=MethodTrace.Requirement.ID+"-"+MethodTrace.Method.Owner.ID;
MethodTrace.Method.Owner.DeveloperGold=classTraceHashMap.get(reqClass).DeveloperGold;
System.out.println(reqMethod+"-");
System.out.println(MethodTrace.Method.Owner.DeveloperGold);
methodtraceHashMap2.putIfAbsent(reqMethod, MethodTrace);
System.out.println("WE ARW IN THE LOOP "+methodtraceHashMap2.get("1-1"));
methodtraceHashMap2.putIfAbsent(reqMethod+"_"+System.currentTimeMillis(), MethodTrace);
System.out.println("WE ARW IN THE LOOP "+methodtraceHashMap2.get("1-1"));
}

Can't modify/remove a field from an ActivityNode using sbt

I created an ActivityNode (an Entry) and I can add custom fields with the
setFields(List<Field> newListField)
fonction.
BUT
I am unable to modify these fields. (In this case I try to modify the value of the field named LIBENTITE)
FieldList list = myEntry.getTextFields();
List<Field> updatedList = new ArrayList<Field>();
//I add each old field in the new list, but I modify the field LIBENTITE
for(Field myField : list){
if(myField.getName().equals("LIBENTITE")){
((TextField)myField).setTextSummary("New value");
}
updatedList.add(myField);
}
myEntry.setFields(updatedList);
activityService.updateActivityNode(myEntry);
This code should replace the old list of fields with the new one, but I can't see any change in the custom field LIBENTITE of myEntry in IBM connections.
So I tried to create a new list of fields, not modifying my field but adding a new one :
for(Field myField:list){
if(!myField.getName().equals("LIBENTITE")){
updatedList.add(myField);
}
}
Field newTextField = new TextField("New Value");
newTextField .setFieldName("LIBENTITE");
updatedList.add(newTextField );
And this code is just adding the new field in myEntry. What I see is that the other custom fields did not change and I have now two custom fields named LIBENTITE, one with the old value and the second with the new value, in myEntry.
So I though that maybe if I clear the old list of Fields, and then I add the new one, it would work.
I tried the two fonctions
myEntry.clearFieldsMap();
and
myEntry.remove("LIBENTITE");
but none of them seems to work, I still can't remove a custom field from myEntry using SBT.
Any suggestions ?
I have two suggestions, as I had (or have) similar problems:
If you want to update an existing text field in an activity node, you have to call node.setField(fld) to update the field in the node object.
Code snippet from my working application, where I'm updating a text field containing a (computed) start time:
ActivityNode node = activityService.getActivityNode(id);
node.setTitle(formatTitle()); // add/update start and end time in title
boolean startFound = false;
// ...
FieldList textfields =node.getTextFields();
Iterator<Field> iterFields = textfields.iterator();
while (iterFields.hasNext()) {
TextField fld = (TextField) iterFields.next();
if (fld.getName().equals(Constants.FIELDNAME_STARTTIME)) {
fld.setTextSummary(this.getStartTimeString()); // NOTE: .setFieldValue does *not* work
node.setField(fld); // write updated field back. This seems to be the only way updating fields works
startFound=true;
}
}
If there is no field with that name, I create a new one (that's the reason I'm using the startFound boolean variable).
I think that the node.setField(fld) should do the trick. If not, there might be a way to sidestep the problem:
You have access to the underlying DOM object which was parsed in. You can use this to tweak the DOM object, which finally will be written back to Connections.
I had to use this as there seems to be another nasty bug in the SBT SDK: If you read in a text field which has no value, and write it back, an error will be thrown. Looks like the DOM object misses some required nodes, so you have to create them yourself to avoid the error.
Some code to demonstrate this:
// ....
} else if (null == fld.getTextSummary()) { // a text field without any contents. Which is BAD!
// there is a bug in the SBT API: if we read a field which has no value
// and try to write the node back (even without touching the field) a NullPointerException
// will be thrown. It seems that there is no value node set for the field. We
// can't set a value with fld.setTextSummary(), the error will still be thrown.
// therefore we have to remove the field, and - optionally - we set a defined "empty" value
// to avoid the problem.
// node.remove(fld.getName()); // remove the field -- this does *not* work! At least not for empty fields
// so we have to do it the hard way: we delete the node of the field in the cached dom structure
String fieldName = fld.getName();
DeferredElementNSImpl fldData = (DeferredElementNSImpl) fld.getDataHandler().getData();
fldData.getParentNode().removeChild(fldData); // remove the field from the cached dom structure, therefore delete it
// and create it again, but with a substitute value
Field newEmptyField = new TextField (Constants.FIELD_TEXTFIELD_EMPTY_VALUE); // create a field with a placeholder value
newEmptyField.setFieldName(fieldName);
node.setField(newEmptyField);
}
Hope that helps.
Just so that post does not stay unanswered I write the answer that was in a comment of the initial question :
"currently, there is no solution to this issue, the TextFields are read-only map. we have the issue recorded on github.com/OpenNTF/SocialSDK/issues/1657"

Querying Sharepoint - Value does not fall within the expected range

I'm attempting to retrieve the value of a listitem but keep getting a ArgumentException - Value does not fall within the expected range.
My code is as follows:
if (resultList.Count > 0)
{
SPListItem result = resultList[0];
if (result[Column] != null)
{
return result[Column].ToString();
}
}
In the immediate window I can verify the column does exist and the value can be found in the object tree structure.
result.Fields.GetField(Column).Id
returns a Guid but using it to retrieve the value of the Field results in another ArgumentException:
result[result.Fields.GetField(Column).Id]
This could happen if you get your list item collection from view (list.GetItems(view)) or from query with ViewFields property set, in this case only the fields included in ViewFields are returned.
You need to use InternalName of the field to get its value from SPListItem
result[result.Fields.GetField(Column).InternalName]

MissingRequiredFields property on SPListItem always returning true after initial validation

I am updating some list items through code.
Here is an example of what I am trying to do
SPListItem item = GetListItem();
item["Field1"] = GetField1ValueFromControl();
item["Field2"] = GetField2ValueFromControl();
item.Update();
if (!item.MissingRequiredFields)
{
SuccessRedirect();
}
else
{
Error("Fields missing");
}
In this example the Field2 is set as a required field, so if the user doesn't enter a value then it would show an error and they could enter a value.
The problem I seem to be having is that after the first error, even after they have entered a value for the required field the MissingRequiredFields property is still returning true after they have resubmitted the page
Any one got any ideas?
I worked this out.
You need to use the Page.IsValidated method to check the controls.
The item will always update whether the required fields are entered or not.
The MissingRequiredFields is not valid until after the update.

Core Data uniqueness

Is there any way I can validate a value updated in a Core Data entity's property against values of the property in other entities in the collection?
At the moment I create an entity with some default values, add it to arrangedObjects, then get the user to modify the various property values. However, I would like to check a particular property and make sure there're no other entities in the array with the same value for that property. What's the best way to do this?
Many thanks,
Dany.
Manually checking is only a few lines of code with a fast enumeration loop:
BOOL unique = YES;
for (NSManagedObject *obj in collection) {
if (obj.property == value) {
unique = NO;
break;
}
}

Resources