The method was called on null

NoSuchMethodError: The method 'toString' was called on null.

Quick Answer

You tried to call a method on a variable that was null.

Why This Happens

In Dart, calling any method on a null reference throws a NoSuchMethodError. This often happens with uninitialized variables or when a function returns null unexpectedly. With null safety enabled, use the ?. operator or ensure proper initialization.

The Problem

class User {
  String? name;
}
final user = User();
print(user.name.toUpperCase()); // name is null

The Fix

class User {
  String? name;
}
final user = User();
print(user.name?.toUpperCase() ?? 'N/A');

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: The method 'X' was called on null. This tells you which method was invoked on a null reference.

  2. 2

    Find the cause

    Check the stack trace to find the variable that was null, and trace back to where it should have been initialized.

  3. 3

    Apply the fix

    Use null-aware method calls (?.) or ensure the variable is properly initialized before calling methods on it.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free