Coding⏱️ 2 min read📅 2026-05-31

How to Fix: What causes error "No enclosing instance of type Foo is accessible" and how do I fix it?

The error occurs because the compiler is unable to find an enclosing instance of type Hello for class Thing. This happens when a nested class is not properly defined.

Quick Answer: To fix this, define the nested class as static or make it an inner class with access modifier.

The error "No enclosing instance of type Foo is accessible" occurs when you try to access a non-static nested class from outside the class. In your case, the Thing class is a non-static nested class inside the Hello class.

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Accessing a Nested Class from Outside the Class

  1. Step 1: Remove access modifier from the nested class.

Method 2: Making a Static Nested Class

  1. Step 1: Add the static keyword to the nested class.

🎯 Final Words

[Wrap-up]

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions