2

Hi everyone I am developing an application where I need to use the Camera and I'm having this problem on my code:

No enclosing instance of type Camera is accessible. Must qualify the allocation with an enclosing instance of type Camera (e.g. x.new A() where x is an instance of Camera) on line "this.preSize_ = new Camera(0,0); Any help? or suggestion?

private void setupCamera()
  {
    this.camera_ = Camera.open();
    Camera localCamera = this.camera_;
    localCamera.getClass();
    this.preSize_ =  new Camera.Size(0,0);
    Camera.Parameters localParameters = this.camera_.getParameters();
    Iterator<Camera.Size> localIterator1 = localParameters.getSupportedPreviewSizes().iterator();
    Camera.Size localSize2;
    do
    {
      if (!localIterator1.hasNext())
        break;
      localSize2 = (Camera.Size)localIterator1.next();
      this.preSize_ = localSize2;
    }
    while ((localSize2.width != this.previewWidth) && (localSize2.height != this.previewHeight));
    localParameters.setPreviewSize(this.preSize_.width, this.preSize_.height);
    Iterator<Camera.Size> localIterator2 = localParameters.getSupportedPictureSizes().iterator();
    Camera.Size localSize1;
    do
    {
      if (!localIterator2.hasNext())
        break;
      localSize1 = (Camera.Size)localIterator2.next();
      this.procSize_ = localSize1;
    }
    while ((localSize1.width != this.processWidth) && (localSize1.height != this.processHeight));
    localParameters.setPictureSize(this.procSize_.width, this.procSize_.height);
    this.camera_.setParameters(localParameters);
    this.camera_.setDisplayOrientation(90);
    try
    {
      this.camera_.setPreviewDisplay(this.surfaceHolder_);
      this.camera_.startPreview();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }
  }
Yourange
  • 158
  • 10
  • What is the type of `this.preSize_`? Is the nested class `Camera.Size` static or not? (If not, you can only create it in the context of a `Camera` object). – Jesper Apr 18 '13 at 08:27
  • @Jesper: Any suggestion? on `this.preSize` – Yourange Apr 18 '13 at 09:04
  • Which `Camera` class are you importing? There are two `Camera` classes in Android: `android.hardware.Camera` and `android.graphics.Camera` I have had a problem in the past where Eclipse would automatically import the wrong one. – Aleks G Apr 18 '13 at 09:30
  • Possible duplicate of [No enclosing instance of type Server is accessible](http://stackoverflow.com/questions/7901941/no-enclosing-instance-of-type-server-is-accessible) – Raedwald Mar 02 '16 at 22:29
  • 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 22:38

1 Answers1

3

Size class is a non-static class of Camera. So you can create it only from enclosing instance of Camera class. Like this:

this.preSize_ = localCamera.new Size(0,0);
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99