xml parser terminated Objective-C - objective-c

I want to pars my xml file in objective-c, but I got an error
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<Presentation1Name 0x74592f0> setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key slide.'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1bfb1 0xb7d711 0xafeec8 0xafe9b7 0x5129 0xbb11c7 0x48c65ee
0x48c5f07 0xbaf6d2 0x2008 0x157b7 0x15da7 0x16fab 0x28315 0x2924b 0x1acf8 0x1beedf9
0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x167da 0x1865c 0x1e5d
0x1d85)
libc++abi.dylib: terminate called throwing an exception
(lldb)
ment to lowercase presentation , I don"t have an error bu I can not pars the label="presentation1" but when I change it to Upercase P -> Presentation I can pars it but with terminated process
Would you please give me some hint for finding the problem?

aPresentation is your own class so its hard to know exactly what its made up of. However your error is coming up when you try to do (unless there is more code that your not showing) :
[aPresentation setValue:currentElementValue forKey:elementName];
here you are saying you have a property in the object aPresentation with the name elementName; specifically your error is saying there is no property with the name "slide"
Is there a property (variable) with the name "slide"? Apparently not.
I would suggest hard coding what the elementName is because apparently they are not lining up with your class.
According to the xml your property (within aPresentation) should be named "slides" so either rename the property in your class to slides or just change element name into what you know it to be.
[aPresentation setValue:currentElementValue forKey:#"slideLabel"];
some of this is guess work without seeing the class structure of Presentation1Name
I would also like to point out some conventions you are not following which makes this code very hard to read. Property names should be capitalized (first letter), including numbers in your class names is ok but not used very often and probably not needed in this case. you are checking if the elementName is Slides or slide and really that stuff shouldnt change and you should be able to remove one of those statements. i would also recommend to always use brackets, some of your else statments dont

Related

Tips for interpretation stack trace, invalid comparison of objects (VB.Net)

I'm currently interning for a software role and trying to get better with debugging and reading stack traces and was wondering if I could get some input/tips with an exception/bug I am getting.
I'm currently getting an error with some software (GUI interface) that basically throws an exception when I try to sort the folder view/list view by the "Size" column (farthest right column in image below) by clicking on that column header. The stack trace looks like its saying it can't compare an "ASString" object with an "ASSort" data object, which looks like those objects get passed as parameters into an ".CompareTo(Object x, Object y)" method.
I just wanted to make sure I was reading the stack trace correctly by reading the top-most exception, which seems to be the one saying that it's comparing invalid objects. Which makes me think I need to fix some casting somewhere in the source code where the .CompareTo(Object x, Object y) method is called.

Unable to observe an array of objects (mobx)

According to the docs: https://mobx.js.org/refguide/array.html
I should be able to observe an array.
observe(listener, fireImmediately? = false) Listen to changes in this
array. The callback will receive arguments that express an array
splice or array change, conforming to ES7 proposal. It returns a
disposer function to stop the listener.
However I'm getting an exception when I do so within my app:
core.js:1350 ERROR Error: Uncaught (in promise): Error: [mobx] Cannot obtain administration from Neil Clayton,Ralph Lambert,Suzie Legg
at invariant (mobx.module.js:2652)
at fail$1 (mobx.module.js:2647)
at getAdministration (mobx.module.js:1967)
at observeObservable (mobx.module.js:3606)
at observe (mobx.module.js:3603)
at ObjectChangeTracker.webpackJsonp.683.ObjectChangeTracker.installObserverDirectlyOn (orm-change-detection.ts:258)
I'm unsure why getAdministration() is falling through.
I was under the impression I could pass anything into observe() (either a JS Object, real class or array thereof).
Am I mistaken that I can observe an array?
It turns out I was trying to observe a direct 'Array'.
This was happening because I was iterating the parent object keys, and getting the values by doing parent[propertyName]. Where 'propertyName' is provided by some other object (i'm intentionally leaving out specifics so as to not complicate my answer).
This was a couple of days ago now, but from memory this caused access via a getter, which had a side effect (returned a sorted array, new object, that wasn't observable).
If instead I got the value by the private field directly, and then observed the actual ObservableArray, my problems disappeared.
So, no longer convinced my question is valid.
Code is here: https://github.com/scornflake/scheduler
(but not expecting anyone to take a look, it's reasonably convoluted at the moment)

Optaplanner 6.1.0 cr1

I am trying to implement a Value Range for an entities planning variable. The variable is defined as
#PlanningVariable(valueRangeProviderRefs = {"xPosRange"})
public BigDecimal getXCenter()
{
return xCenter;
}
The ValueRangeProvider is specified as
#ValueRangeProvider(id = "xPosRange")
public CountableValueRange<BigDecimal> getXPositions()
{
return ValueRangeFactory.createBigDecimalValueRange(new BigDecimal(0.0,
MathContext.DECIMAL64), new BigDecimal(maxLength, MathContext.DECIMAL64));
}
Ideally I would like to have this within the Planning Entity. However, the values are never changed when the solution is being solved. The same is true when the "ValueRangeProvider" is added to the solution.
Do the "CountableValueRange" collections need to be added to the problem facts?
If so how, adding
facts.addAll(getXPositions());
raises an argument mismatch error.
I have tried to add the following to the xml config file
<changeMoveSelector>
<valueSelector>
<variableName>xCenter</variableName>
</valueSelector>
</changeMoveSelector>
However, this raises a runtime error stating the xCenter has no "getter" within the entity.
The selectorConfig (ValueSelectorConfig(xCenter)) has a variableName (xCenter) for
entityClass (packetName.Part) that does not have that as a getter.
Check the spelling of the variableName (xCenter)
Please can anyone point me in the correct direction. Thank you.
"Do the CountableValueRange collections need to be added to the problem facts?" No. That would require enumerating them, which is unrealistic for large value ranges (all possible longs for example).
"However, this raises a runtime error stating the xCenter has no getter within the entity." I suspect that your issue has nothing to do with the use of the CountableValueRange<BigDecimal>, but has everything to do with the variable property name xCenter. Motivation for this theory:
The error message speaks about not finding the planning variable (= step 2), not about not finding the value range (= step 3). It did find the planning entity successfully (= step 1).
The JavaBeans specification related to the getters of getXCenter() and getAFoo() and getHTTPSomething() are strange/illogical, if I recall correctly. I suspect getXCenter() leads to a property name of XCenter instead of xCenter (and yes, the JavaBeans spec suck in that regard, but OptaPlanner has to adhere to the JavaBeans spec).
I've improved the error message for 6.1.0.CR2, so you 'd get something like this:
Exception in thread "main" java.lang.IllegalArgumentException: The selectorConfig (ValueSelectorConfig(pEriod)) has a variableName (pEriod) which is not a valid planning variable on entityClass (class org.optaplanner.examples.curriculumcourse.domain.Lecture).
The variableName (pEriod) for entityClass (class org.optaplanner.examples.curriculumcourse.domain.Lecture) does not exists as a property (getter/setter) on that class.
Check the spelling of the variableName (pEriod). It probably needs to be correctedVariableName (PEriod) instead because the JavaBeans spec states the first letter should be a upper case if the second is upper case.
at org.optaplanner.core.config.heuristic.selector.SelectorConfig.deduceVariableDescriptor(SelectorConfig.java:100)
at org.optaplanner.core.config.heuristic.selector.value.ValueSelectorConfig.buildValueSelector(ValueSelectorConfig.java:198)
at org.optaplanner.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig.buildBaseMoveSelector(ChangeMoveSelectorConfig.java:68)
at org.optaplanner.core.config.heuristic.selector.move.MoveSelectorConfig.buildMoveSelector(MoveSelectorConfig.java:187)

How does compiler handle missing parameter names in Objective-C?

I have run into someone else's code that declares methods like this:
- (void) method:(id)a:(NSString*)b { }
The compiler accepts this code, giving just a warning:
'a' used as the name of the previous parameter rather than as part of the selector
The code declares various functions with this type and then invokes them through NSSelectorFromString, using the signature "methodname::". So it's all consistent.
I wonder if that method signature is just a mistake or if there's more to it. Since it's used consistently in the code, I don't think this is a typo. I don't know the author so I can't tell if this is code of a genius or the opposite.
Is 'b' an anonymous parameter? (If so, shouldn't it rather be written with a blank between the "a" and ":" to indicate this better?) I can't find anything about anon parms in the ObjC docs, though.
Will there be any change in behavior if I change the syntax to giving the second parameter a name, and fixing the signature reference accordingly? I plan to make this change to get rid of the warnings, but I wonder I might create an issue that I'm not aware of.
Everything you describe is pretty much correct. It's very bad style, but technically it's just a two-argument selector which happens to have no text before the second :. I wouldn't call b an anonymous argument since you can still give it a name, it just doesn't have any descriptive text before it as part of the selector's name.
Yes, there should probably be a space after the a.
If you want to rename it, you can use Xcode's standard Refactor->Rename functionality and just insert some text before the second :. It will update all the references and you should encounter no problems.
You can use the signature method::, even though it is not recommended by most people.
Just insert a space character before each : separating the parameters, and the compiler is happy:
- (void) method:(id)a :(NSString*)b
On page 16 "Message Syntax" of The Objective-C Programming Language
this is called an "unlabeled argument", or an "argument without keyword".
Of course you can change it to
- (void) method:(id)a withB:(NSString*)b
but this changes the selector to method:withB:.

Obj-C, Receiver in message expression is an uninitialized value, analyzer warning?

I'm getting the following analyzer warning on this line...
if ([datStartDate compare:now] == NSOrderedDescending) {
Receiver in message expression is an uninitialized value
The line of code occurs in the middle of an IBAction.
What am I doing wrong?
If you expand the disclosure triangle next to the error (in the error navigator on the left side), it'll show you the exact code path that leads to a situation where the value is not initialized.
You may think "But, analyzer, really, that can never happen.". While that may be true, you are creating an assumption in your code that may not hold true in the future due to bug or intentional change. That increases the fragility of your codebase and will lead to maintenance headaches.
Fix the code such that it is explicit and remove the assumption.
There is at least one code path that can lead to this line with datStartDate still being uninitialized. That means you have never assigned an object to datStartDate, not even nil.