0

I am trying to put my separate Java files in 1 class. It looks like this.

public class oneClass {
    class Request {
        public double a;
        public double b;
        public double c;

        public Request(double a, double b, double c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }

    public static class Controller {
        public static void main(String[] args) {   
            Request req = new Request(time, 0, 0);

            // some code
        }
    }
}

but I ran into an error

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instance of type oneClass is accessible. Must qualify the allocation with an enclosing instance of type problem2 (e.g. x.new A() where x is an instance of problem2).

What's going on?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
kevin_b
  • 803
  • 4
  • 16
  • 34
  • 1
    Use `static class Requst` instead of `class Request`. –  Feb 23 '16 at 05:19
  • 2
    Possible duplicate of [No enclosing instance of type is accessible](http://stackoverflow.com/questions/18690770/no-enclosing-instance-of-type-is-accessible) – ΦXocę 웃 Пepeúpa ツ Feb 23 '16 at 05:21
  • Possible duplicate of [Java - No enclosing instance of type Foo is accessible](http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-accessible) – fabian Mar 03 '16 at 23:47

1 Answers1

0

You need to make Request a static class if you want to construct it outside an instance of your outer class.

shmosel
  • 49,289
  • 6
  • 73
  • 138