Error while parsing xml attribute - xml-parsing

I am getting error on
I.ID=((Element) nl.item(i)).getAttributes().getNamedItem("ID").getNodeValue();
the error is that
getNamedItem required INT and found String
When i give an Int value then the error said that it required String and found Int.

Issue Resolved.
getNamedItem is returning String value while ID is an integer value. so i put string to integer parser which resolved my issue.

Related

Null safety type promotion when assigning non-null value literal

In nullsafety.dartpad.dev if I write the following code:
void main() {
String? name = 'Bob';
print(name.length);
}
I get the following compile-time error:
An expression whose value can be 'null' must be null-checked before it can be dereferenced
And the following runtime error:
Property 'length' cannot be accessed on 'String?' because it is potentially null.
The Type promotion on null checks documentation says:
The language is also smarter about what kinds of expressions cause promotion. An explicit == null or != null of course works. But explicit casts using as, or assignments, or the postfix ! operator we’ll get to soon also cause promotion. The general goal is that if the code is dynamically correct and it’s reasonable to figure that out statically, the analysis should be clever enough to do so.
Question
There is no possible way name could be null in the code above. The documentation also says assignments should cause type promotion. Am I misunderstanding type promotion or is this a bug in DartPad?
Clarification
Since a couple of the answers are providing workaround solutions to the error messages, I should clarify that I'm not trying to solve the coding problem above. Rather, I'm saying that I think the code should work as it it. But it doesn't. Why not?
This answer is in response to the bounty that was added to the original question. The bounty reads:
Please explain how String? is different from String and how type
promotion works in Dart.
String? vs String
The type String? can contain a string or null. Here are some examples:
String? string1 = 'Hello world';
String? string2 = 'I ❤️ Dart';
String? string3 = '';
String? string4 = null;
The type String, on the other hand, can only contains strings (once null safety is a part of Dart, that is). It can't contain null. Here are some examples:
String string1 = 'Hello world';
String string2 = 'I ❤️ Dart';
String string3 = '';
If you try to do the following:
String string4 = null;
You'll get the compile-time error:
A value of type 'Null' can't be assigned to a variable of type 'String'.
The String type can't be null any more than it could be an int like 3 or a bool like true. This is what null safety is all about. If you have a variable whose type is String, you are guaranteed that the variable will never be null.
How type promotion works
If the compiler can logically determine that a nullable type (like String?) will never be null, then it converts (or promotes) the type to its non-nullable counterpart (like String).
Here is an example where this is true:
void printNameLength(String? name) {
if (name == null) {
return;
}
print(name.length);
}
Although the parameter name is nullable, if it actually is null then the function returns early. By the time you get to name.length, the compiler knows for certain that name cannot be null. So the compiler promotes name from String? to String. The expression name.length will never cause a crash.
A similar example is here:
String? name;
name = 'Bob';
print(name.length);
Although name is nullable here, too, the string literal 'Bob' is obviously non-null. This also causes name to be promoted to a non-nullable String.
The original question was regarding the following:
String? name = 'Bob';
print(name.length);
It seems that this should also promote name to a non-nullable String, but it didn't. As #lrn (a Google engineer) pointed out in the comments, though, this is a bug and when null safety comes out, this will also work like the previous example. That is, name will be promoted to a non-nullable String.
Further reading
Sound null safety
Type promotion on null checks
I understand what you are saying. Try this out.
In order for type promotion to work you must first confirm that the value is not null as the documentation says.
As you can see in the picture dart is able to do the type promotion or understand that name is not going to be null because it checks that on the if statement beforehand.
But if using it outside the if statement without checking if it is not null beforehand, dart knows it can be assigned null anytime again. That’s why it encourages always checking if it is null. Because any instatiated variable ( a variable with a value assigned) can be assigned null in the future.

how to cast Edm.Guid to Edm.String in odata

how to cast guid into string in odata, i have tried the $filter=(startswith(cast(CustomerID, 'Edm.String'),'1')) but it throws exception Unknown function 'cast'.
To perform a cast, the type shouldn't be in quotes. So it should be:
$filter=startswith(cast(CustomerID, Edm.String),'1')
(I also removed the extra brackets)

Realm on iOS throws "Invalid value '301' for property'code'" where 'code' is of type Int

code is an integer, so it's declared as an Int in my subclass.swift file. The subclass is in the same format as the JSON, to enable saving the JSON directly to Realm.
I get this JSON:
...
"code": 301
...
And this is how I'm saving it:
realm.create(Student.self, value: jsonStudent, update: true)
But Realm throws this:
failed: caught "RLMException", "Invalid value '301' for property 'code'"
At first I thought the '301' might be getting parsed as a string, but that was not the case, calling 'dynamicType' on it in the debugger returns NSCFNumber, which is expected.
What's wrong?
NSJSONSerialization will convert {"code": 301} to an NSNumber of type q, which is integer. So the fact that you're getting an invalid property implies that the code property on your Realm model is of a different type (maybe Float or Double)?
Could you share your model definition here?
If your code property is actually Int or a variation thereof (Int32, Int64, etc.), this would imply there's a bug in Realm and I'd recommend that you open an issue at https://github.com/realm/realm-cocoa/issues.

WebSecurity.ResetPassword unable to work

I have MVC4 application and i am using default membership. I have changed UserId from int to Bigint. When i call WebSecurity.ResetPassword with token and new password it is showing error :
Cannot implicitly convert type 'long' to 'int?'. An explicit conversion exists (are you missing a cast?)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'long' to 'int?'. An explicit conversion exists (are you missing a cast?)
Source Error:
Dim newpassw As String = mdl.Password
Dim response As Boolean = WebSecurity.ResetPassword(mdl.PasswordResetToken, newpassw)
When i changed UserId from Bigint to int its working fine. But i need Bigint instead of int for UserId in database. How to do Websecurity.ResetPassword for Bigint?

list_to_float error

I understand that list_to_float("123") gives a badarg error but why list_to_float(["12.34"]) gives also the same error ?
Try
list_to_float("12.34")
list_to_float accepts a String and it returns a float whose text representation is the String.

Resources