Questions tagged [null-check]

A check to see that an object has been instantiated.

A check to see that an object has been instantiated.

Typically, in a OO programming language, this is to see whether an object has been created or not.

e.g (Java example)

public void doStuff(Object obj) {
    if (obj != null) {
        // Do stuff with the object
    }
}
217 questions
0
votes
0 answers

Null check operator used on null value error even if I didn't use any

This is the widget the error is pointing to Container( height: 350, child: GetBuilder( id: imageContainer, builder: (_) { if…
0
votes
1 answer

Null check operator used on null value when I have defined a model the particular list using null safety in flutter

I want to check if list is empty then show some image and if it is not I want to show the contents of the list but I am getting an error when checking if the list is empty.This is my model class import 'dart:convert'; class ProductModel { …
0
votes
1 answer

Flutter/Dart - Null Check Error with data provided by PageViewBuilder

I'm getting the following nullcheck errors on data provided by a PageViewBuilder; The following _CastError was thrown building: Null check operator used on a null value When the exception was thrown, this was the stack: #0 …
Meggy
  • 1,491
  • 3
  • 28
  • 63
0
votes
1 answer

The argument type 'Object' can't be assigned to the parameter type 'Timestamp' - Flutter

I have a model who have "date" as a final parameter . class WalletTransaction extends Equatable { final String id; final String amount; final String description; final bool isDepense; final Timestamp date; WalletTransaction( …
lkhadirn
  • 30
  • 4
0
votes
1 answer

Proper way to null check Vue object with "__proto__" and/or "__ob__" property

I would like to know a quick and clean way to check if objects with just __ob__ or __proto__ properties are empty. Now I have to "guess" a value inside my object and null check that instead of the object itself. Example: const myObject =…
Håkon
  • 19
  • 2
0
votes
1 answer

Typescript, object is possibly undefined inside null check

Im wondering, how is this code giving object is possibly undefined error if (newFocus) { if (viewCache[viewId] !== undefined) { dispatch(ViewActions.focusOn(viewCache[viewId].focus)); } else { …
Clomez
  • 1,410
  • 3
  • 21
  • 41
0
votes
3 answers

Using Java Optional within stream mapping

I have code like this: public void processList(List list) { for (String item : list) { Object obj = getObjectForString(item); if (obj != null) { doSomethingWithObject(obj); } else { …
Adam
  • 13
  • 2
0
votes
2 answers

Typescript and value can't be null

I have a typescript code as follows: constructor(c?: IContact) { this.id = c ? c.id : null; this.caseId = c ? c.caseId : null; this.name = c ? c.name : ''; this.email = c ? c.email : ''; this.isPrimary = c ? c.isPrimary :…
termine
  • 55
  • 2
  • 8
0
votes
1 answer

Recursively check for any null / undefined keys / values in an object using Javascript

I have input like {'OR': [false, true, {'AND': [true, true]}]} and so on. It evaluates to (false || true || (true && true)) which is true I need to check if input has any key / value which is null / undefined / numeric key / not in above…
user544079
  • 16,109
  • 42
  • 115
  • 171
0
votes
2 answers

How do I refactor do fix redundant null check

Getting a redundant null check error in the following code block. Can someone help me refactor it: private Date pickRecent(Date d1, Date d2, Date d3, Date crd) { logger.debug("d1: " + d1 + " d2: " + d2 + " d3: " + d3 + " crd: " + crd); …
raptor
  • 1
  • 1
0
votes
1 answer

Null Checking of a model property in JS within a Razor View

My model property MobileNumber may have a value or may be null. I am trying to check for this within my View, using JS. var mobileNumber = @String.IsNullOrEmpty((Model.MobileNumber)); However the browser console doesn't like this: Uncaught…
0
votes
1 answer

What is most concise way to check for null or whitespace before displaying data in Blazor components?

I would like to reduce the amount of code in the following code block: @if (!string.IsNullOrWhiteSpace(employee?.HomeAddressStreet)) { @employee?.HomeAddressStreet
} Ideally, I would like one line of code without logic to decipher. …
Paul Van Gundy
  • 129
  • 3
  • 4
0
votes
1 answer

How can I factor the behaviour of static methods in a superclass?

I need to create a series of transformer classes that transform an object into an other one. They are of the form class Transformer1 { public static AnotherClass transform(MyClass source) { return AnotherClass.newBuilder() …
Bentaye
  • 9,403
  • 5
  • 32
  • 45
0
votes
2 answers

How to check sql database table field null or 0 and if so replace it with other column

I have a SQL query; I want to check two columns in query to check if they are null or 0; if so, then I want to replace then with other column's values. Here is my query: I have used coalesce to check if it is null but how can I check for 0 and also…
varun
  • 73
  • 7
0
votes
2 answers

null check in try-with-resources

I've got the following code: try (Connection connection = getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(someSql)) {//stuff} How do I check that connection is not null here? Also, I got a method which…