-1

I am currently creating a 2D Android game using Android Studio. I have created a class called GameView which extends SurfaceView and implements SurfaceHolder.CallBack. However, I am getting the error, "Cannot resolve symbol 'Callback'". I have already checked the SurfaceHolder class and the interface for Callback exists already.

I have already tried cleaning the project and tried looking around the internet for help, but can't seem to solve it. Can someone help me figure out what the problem and how I can solve it?

The code for the GameView class which I wrote so far:

import android.content.Context;
import android.support.annotation.MainThread;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
 * Created by Shreyas on 22/03/2017.
 */
public class GameView extends SurfaceView implements SurfaceHolder.CallBack
{
    private MainThread thread;
    public GameView(Context context)
    {
        super(context);
        getHolder().addCallback(this);
        thread = new MainThread(getHolder(), this);
        setFocusable(true);
    }
    public void surfaceDestroyed(SurfaceHolder holder)
    {

    }
}

Thank you.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ShreJ
  • 1
  • 1
  • 3

2 Answers2

1

Try this quick fix: add this line to your import code

import android.view.SurfaceHolder.Callback;
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
0

Wow that was annoying - my fix was make sure auto import is on in Android studio (Preferences->Editor->General->Auto Import) turn everything on then in my code made a fake variable and hand typed it in and viola it asked which library to import

example: x = new Callback... and it shows the list of options