Error decoder

Paste an error message into the search to learn why it appeared and how to fix it.

Common errors

PythonNameError: name 'nmae' is not definedUnknown name

Why: You used a variable that does not exist: a typo, or it was not created yet.

How to fix: Check the spelling and create the variable before using it.

With the error
name = "Ola"
print(nmae)
Fixed
name = "Ola"
print(name)
PythonTypeError: can only concatenate str (not "int") to strString plus number

Why: The `+` operator cannot join a string with a number.

How to fix: Convert the number with `str()` or use an f-string.

With the error
print("Age: " + 5)
Fixed
print("Age: " + str(5))
PythonIndentationError: expected an indented block after 'if' statement on line 2Missing indentation

Why: The body of a block after `if` must be indented.

How to fix: Indent the lines inside the block (4 spaces).

With the error
x = 1
if x:
print(x)
Fixed
x = 1
if x:
    print(x)
PythonSyntaxError: '(' was never closedUnclosed parenthesis

Why: A parenthesis was opened but never closed.

How to fix: Add the closing parenthesis `)`.

With the error
print("hi"
Fixed
print("hi")
PythonIndexError: list index out of rangeIndex out of range

Why: A list of three items has indexes 0, 1, 2. Index 3 does not exist.

How to fix: Use an index from 0 to `len(a) - 1`, or `a[-1]` for the last item.

With the error
a = [1, 2, 3]
print(a[3])
Fixed
a = [1, 2, 3]
print(a[2])
PythonKeyError: 'b'Missing key

Why: The dictionary has no key "b".

How to fix: Check the key with `in` or read it with the `get` method.

With the error
d = {"a": 1}
print(d["b"])
Fixed
d = {"a": 1}
print(d.get("b", 0))
JavaScriptReferenceError: total is not definedVariable not declared

Why: You use a variable that was never declared.

How to fix: Declare it with `let` or `const` before using it.

With the error
console.log(total);
Fixed
const total = 10;
console.log(total);
JavaScriptTypeError: Assignment to constant variable.Changing a constant

Why: The variable is declared with `const` and cannot be reassigned.

How to fix: Use `let` if the value must change.

With the error
const n = 1;
n = 2;
Fixed
let n = 1;
n = 2;
JavaScriptTypeError: Cannot read properties of undefined (reading 'name')Property of undefined

Why: You read `.name` from `undefined`: there is no object.

How to fix: Make sure the object exists, or use `user?.name`.

With the error
const user = undefined;
console.log(user.name);
Fixed
const user = undefined;
console.log(user?.name);
JavaScriptTypeError: x is not a functionNot a function

Why: You call with `()` a value that is not a function.

How to fix: Call only functions, and use numbers or strings without parentheses.

With the error
const x = 5;
x();
Fixed
const x = () => 5;
x();
JavaScriptSyntaxError: Unexpected token ';'Unexpected token

Why: The array was not closed with `]`, so `;` appeared where it was not expected.

How to fix: Close the brackets properly.

With the error
const a = [1, 2;
Fixed
const a = [1, 2];
JavaScriptReferenceError: Cannot access 'x' before initializationUsed before declaration

Why: A `let` or `const` variable is read before the line that creates it.

How to fix: Move the declaration above the first use.

With the error
console.log(x);
let x = 1;
Fixed
let x = 1;
console.log(x);
PHPWarning: Undefined variable $nameUndefined variable

Why: Nobody created `$name`, or the name has a typo.

How to fix: Assign a value before using it.

With the error
<?php
echo $name;
Fixed
<?php
$name = "Ola";
echo $name;
PHPParse error: syntax error, unexpected token "echo", expecting "," or ";"Missing semicolon

Why: The previous line does not end with `;`.

How to fix: End every statement with `;`.

With the error
<?php
echo "hi"
echo "x";
Fixed
<?php
echo "hi";
echo "x";
PHPWarning: Undefined array key 5Undefined array key

Why: The array has no element with key 5.

How to fix: Check the key with `isset` or the `??` operator.

With the error
<?php
$a = [1];
echo $a[5];
Fixed
<?php
$a = [1];
echo $a[5] ?? 0;
Godeclared and not used: xUnused variable

Why: Go does not allow a local variable that is never used.

How to fix: Use the variable or remove it.

With the error
package main

func main() {
	x := 5
}
Fixed
package main

import "fmt"

func main() {
	x := 5
	fmt.Println(x)
}
Go"os" imported and not usedUnused import

Why: The package is imported but never used in the code.

How to fix: Remove the unneeded import.

With the error
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println("hi")
}
Fixed
package main

import "fmt"

func main() {
	fmt.Println("hi")
}
Gocannot use "5" (untyped string constant) as int value in variable declarationType mismatch

Why: A string is assigned to an `int` variable.

How to fix: Write the number without quotes, or convert the string with `strconv.Atoi`.

With the error
package main

import "fmt"

func main() {
	var n int = "5"
	fmt.Println(n)
}
Fixed
package main

import "fmt"

func main() {
	var n int = 5
	fmt.Println(n)
}
Javaerror: incompatible types: String cannot be converted to intIncompatible types

Why: A string is put into an `int` variable.

How to fix: Write the number without quotes, or use `Integer.parseInt("5")`.

With the error
public class Main {
    public static void main(String[] args) {
        int x = "5";
        System.out.println(x);
    }
}
Fixed
public class Main {
    public static void main(String[] args) {
        int x = Integer.parseInt("5");
        System.out.println(x);
    }
}
Javaerror: cannot find symbolCannot find symbol

Why: The compiler does not know the variable `totl`: a typo or it was not declared.

How to fix: Fix the name or declare the variable.

With the error
public class Main {
    public static void main(String[] args) {
        int total = 5;
        System.out.println(totl);
    }
}
Fixed
public class Main {
    public static void main(String[] args) {
        int total = 5;
        System.out.println(total);
    }
}
Javaerror: missing return statementMissing return

Why: When the condition is false, the method reaches its end and returns nothing.

How to fix: Add a `return` for every path.

With the error
public class Main {
    static int twice(int n) {
        if (n > 0) {
            return n * 2;
        }
    }
    public static void main(String[] args) {
        System.out.println(twice(2));
    }
}
Fixed
public class Main {
    static int twice(int n) {
        if (n > 0) {
            return n * 2;
        }
        return 0;
    }
    public static void main(String[] args) {
        System.out.println(twice(2));
    }
}
Cwarning: implicit declaration of function 'square' [-Wimplicit-function-declaration]Function not declared

Why: `square` is called but is neither defined nor declared above.

How to fix: Define the function before `main` or add its prototype.

With the error
#include <stdio.h>
int main(void) {
    int n = square(4);
    printf("%d\n", n);
    return 0;
}
Fixed
#include <stdio.h>
int square(int x) { return x * x; }
int main(void) {
    int n = square(4);
    printf("%d\n", n);
    return 0;
}
Cerror: expected ';' before 'return'Missing semicolon

Why: The `printf` line does not end with `;`.

How to fix: Put `;` at the end of the statement.

With the error
#include <stdio.h>
int main(void) {
    printf("hi\n")
    return 0;
}
Fixed
#include <stdio.h>
int main(void) {
    printf("hi\n");
    return 0;
}
Cerror: 'm' undeclared (first use in this function)Undeclared variable

Why: There is no variable `m`: a typo or it was never created.

How to fix: Declare the variable or fix the name.

With the error
#include <stdio.h>
int main(void) {
    int n = 5;
    printf("%d\n", m);
    return 0;
}
Fixed
#include <stdio.h>
int main(void) {
    int n = 5;
    printf("%d\n", n);
    return 0;
}

More in the Lab

Errors are part of learning

Each requirement in the courses has a hint, and you can try as often as you like.