Questions tagged [non-nullable]

232 questions
0
votes
0 answers

Android Studio error when Add data to Database msg Returned a map containing a null key or value (id, null)

Can someone help me? I really need help to solve my Android Studio application. I test my project on SmartPhone and when i want to insert data to database the Logcat on Android Studio says 2022-11-06 03:48:34.113 22617-23221/com.example.golf…
Andry
  • 1
0
votes
1 answer

Can I avoid `!!` everywhere when I'm using Android View Binding with Kotlin?

I'm playing around with Kotlin on Android and one thing makes me confused. When I converted few Fragments from Java to Kotlin I got this: class XFragment : Fragment() { private var binding: FragmentXBinding? = null override fun…
Kamil
  • 13,363
  • 24
  • 88
  • 183
0
votes
1 answer

Warning when assigning non-nullable integer to nullable integer

Nullable a; int b = 2; a = b; a is nullable integer. b is NON-nullable integer. I want to receive warning or error in Visual Studio when a NON-nullable integer is assigned to a nullable integer [a = b]. Is it possible?
Sean C
  • 1
0
votes
0 answers

TypeScript non-null assertion operator does not work

I have a type with a conditional property (in this case 'b') type tp1 = {a: string, b?: Array}; I create an object of this type, where conditional properties are present const a: tp1 = {a: '10', b: [1,2,3]}; I'm trying to log and check how…
0
votes
1 answer

Not null constraint violation for non-existing field

I create the following relational table with a primary key (Liquibase script below):
Rnam
  • 65
  • 1
  • 7
0
votes
1 answer

`T?` references the same type as `T` despite constraint `T : notnull`

I wrote a class called Enumerable that implements IEnumerable and IEnumerator using a lambda function as an alternative to using a generator. The function should return null to indicate the end of the sequence. It allows me to write code such…
Ron Inbar
  • 2,044
  • 1
  • 16
  • 26
0
votes
1 answer

Is there a reason to check if a non-nullable parameter is null?

I'd expect a non-nullable parameter to never ever be null. But I've came across this piece of code in Flutter source. The assertions (and comments) seem redundant (link to the code): /// Creates a route that delegates to builder callbacks. /// …
Ondra Simek
  • 510
  • 2
  • 7
0
votes
1 answer

Non-nullable enum as generic parameter

I am trying to implement this helper function in C# 7.3: public static T? ToEnum(this string enumName) where T : Enum => Enum.TryParse(enumName, out T val) ? val : null; But got a compiler error: Error CS8370 Feature 'nullable…
Xiaoguo Ge
  • 2,177
  • 20
  • 26
0
votes
2 answers

A value of type 'DatabaseHelper?' can't be returned from the constructor 'DatabaseHelper' because it has a return type of 'DatabaseHelper'

static DatabaseHelper? _databaseHelper; DatabaseHelper._craeteInstance(); factory DatabaseHelper(){ if(_databaseHelper == null){ _databaseHelper = DatabaseHelper._craeteInstance(); } return _databaseHelper; …
0
votes
0 answers

What to do for 'Non-Nullable Property Must Contain A Non-Null Value' for property bound at run time

What is standard practice with new enable setting for classes with properties that are bound at runtime that you know the value will not be null? Examples: Strongly typed appsettings.json classes public class CustomSettings { …
Terry
  • 2,148
  • 2
  • 32
  • 53
0
votes
1 answer

Use non-nullable reference types in DTO:s/api objects

I want to use non-nullable reference type in my dto:s/api objects, without getting warnings and without defeating the entire purpose by using them by using the bang operator. Lets say I consume from an GraphQL-endpoints that returns a hierarchy of…
Cowborg
  • 2,645
  • 3
  • 34
  • 51
0
votes
0 answers

Make variable of reference type non-nullable in C#

For example, I have a reference type variable that is guaranteed to be assigned string name = ""; is it possible to make impossible this assignment? name = null; I heard of the ! operator, but as I understand it is only to assure the compiler that…
majorro
  • 61
  • 1
  • 2
  • 8
0
votes
1 answer

The parameter 'builder' can't have a value of 'null' because of its type, but the implicit default value is 'null'

I am trying to use my previous app with the following code, but it seems some updates have happened in Flutter and I get the following Error: import 'package:flutter/material.dart'; class CustomRoute extends MaterialPageRoute { …
GoodMan
  • 542
  • 6
  • 19
0
votes
2 answers

The non-nullable local variable 'title' must be assigned before it can be used. Flutter error

I want to take user input from the textfield widget and assign in title variable as in this code import 'package:flutter/material.dart'; class AddTaskScreen extends StatelessWidget { final Function callBack; // function AddTaskScreen({required…
user16307243
0
votes
1 answer

New flutter rules caused this ERROR: The argument type 'String?' can't be assigned to the parameter type 'String'

I have a code like this: String? _token; DateTime? _expiryDate; String? _userId; Timer? _authTimer; Future tryAutoLogin() async { final prefs = await SharedPreferences.getInstance(); if (!prefs.containsKey('userData')) { …
user11874694