title: How do I get rid of these errors in Android Studio?
body: <p>I am a novice android app programmer and just started to code a game.  I recently found a video where a red square should show up and would be allowed to be dragged.  I made sure of it and copied the code exactly.  Here are all of the pieces of code:</p>
  
  <p><strong>Main Activity:</strong></p>
  
  <pre><code>package com.onemorelaugh.mads;
  
  import android.app.Activity;
  
  import android.os.Bundle;
  import android.view.Window;
  import android.view.WindowManager;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          //makes full screen
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
          //gets rid of title bar
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(new GamePanel(this));
      }
  }
  </code></pre>
  
  <p><strong>GamePanel:</strong></p>
  
  <pre><code>package com.onemorelaugh.mads;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Point;
  import android.graphics.Rect;
  import android.view.MotionEvent;
  import android.view.SurfaceHolder;
  import android.view.SurfaceView;
  
  /**
   * Created by OneMoreLaugh on 8/7/2016.
   */
  public class GamePanel extends SurfaceView implements SurfaceHolder.Callback{
      private MainThread thread;
      private RectPlayer player;
      private Point playerPoint;
  
      public GamePanel(Context context){
          super(context);
          getHolder().addCallback(this);
          thread = new MainThread(getHolder(),this);
          player = new RectPlayer(new Rect(100, 100, 100, 100), Color.rgb(255, 0, 0));
          playerPoint = new Point(150,150);
          setFocusable(true);
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
  
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder){
          thread = new MainThread(getHolder(),this);
  
          thread.setRunning(true);
          thread.start();
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          boolean retry = true;
          while (true) {
              try {
                  thread.setRunning(false);
                  thread.join();
              } catch (Exception e) {e.printStackTrace();}
              retry = false;
          }
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event){
          //return super.onTouchEvent(event);
          switch(event.getAction()){
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
                  playerPoint.set((int)event.getX(), (int)event.getY());
          }
          return true;
      }
  
      public void update() {
          player.update(playerPoint);
      }
  
      @Override
      public void draw(Canvas canvas){
          super.draw(canvas);
          canvas.drawColor(Color.WHITE);
          player.draw(canvas);
      }
  }
  </code></pre>
  
  <p><strong>GameObject:</strong></p>
  
  <pre><code>package com.onemorelaugh.mads;
  
  import android.graphics.Canvas;
  
  /**
   * Created by OneMoreLaugh on 8/7/2016.
   */
  public interface GameObject {
      public void draw(Canvas canvas);
      public void update();
  }
  </code></pre>
  
  <p><strong>RectPlayer:</strong></p>
  
  <pre><code>package com.onemorelaugh.mads;
  
  import android.graphics.Canvas;
  import android.graphics.Paint;
  import android.graphics.Point;
  import android.graphics.Rect;
  /**
   * Created by OneMoreLaugh on 8/7/2016.
   */
  public class RectPlayer implements GameObject {
  
      private Rect rectangle;
      private int color;
  
      public RectPlayer(Rect rectangle, int color){
          this.rectangle = rectangle;
          this.color = color;
      }
      @Override
      public void draw(Canvas canvas){
          Paint paint = new Paint();
          paint.setColor(color);
          canvas.drawRect(rectangle, paint);
  
  
      }
  
      @Override
      public void update(){
  
      }
  
      public void update(Point point){
          rectangle.set(point.x - rectangle.width()/2, point.y - rectangle.height()/2, point.x + rectangle.width()/2, point.y + rectangle.height()/2);
      }
  }
  </code></pre>
  
  <p><strong>MainThread:</strong></p>
  
  <pre><code>package com.onemorelaugh.mads;
  
  import android.graphics.Canvas;
  import android.view.SurfaceHolder;
  
  /**
   * Created by OneMoreLaugh on 8/7/2016.
   */
  
  public class MainThread extends Thread{
      public static final int MAX_FPS = 30;
      private double averageFPS;
      private SurfaceHolder surfaceHolder;
      private GamePanel gamePanel;
      private boolean running;
      public static Canvas canvas;
  
      public void setRunning(boolean running){
          this.running = running;
      }
  
      public MainThread(SurfaceHolder surfaceHolder, GamePanel gamePanel){
          super();
          this.surfaceHolder = surfaceHolder;
          this.gamePanel = gamePanel;
  
      }
  
      @Override
      public void run(){
          long startTime;
          long timeMillis = 1000/MAX_FPS;
          long waitTime;
          int frameCount = 0;
          long totalTime = 0;
          long targetTime = 1000/MAX_FPS;
  
          while(running){
              startTime = System.nanoTime();
              canvas = null;
              try {
                  canvas = this.surfaceHolder.lockCanvas();
                  synchronized (surfaceHolder) {
                      this.gamePanel.update();
                      this.gamePanel.draw(canvas);
                  }
              }catch(Exception e){e.printStackTrace();}
              finally {
                  if(canvas != null){
                      try {
                          surfaceHolder.unlockCanvasAndPost(canvas);
                      }catch(Exception e) {e.printStackTrace();}
                  }
              }
              timeMillis = (System.nanoTime() - startTime)/1000000;
              waitTime =  targetTime - timeMillis;
              try {
                  if (waitTime &gt; 0)
                      this.sleep(waitTime);
              }catch(Exception e){e.printStackTrace();}
              totalTime += System.nanoTime() - startTime;
              frameCount++;
              if (frameCount == MAX_FPS){
                  averageFPS = 1000/((totalTime/frameCount)/1000000);
                  frameCount = 0;
                  totalTime = 0;
                  System.out.println(averageFPS);
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Now I double checked this code and it worked for the guys in the video.  When I try and run it, (I'm using android studio) the emulator pops up and shows the home screen of a phone after being black for a little.  It is like the app crashed.  Below are the error codes <strong>I get:</strong></p>
  
  <pre><code>Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:generateDebugAndroidTestSources, :app:assembleDebug]
  :app:clean
  :app:preBuild UP-TO-DATE
  :app:preDebugBuild UP-TO-DATE
  :app:checkDebugManifest
  :app:preReleaseBuild UP-TO-DATE
  :app:prepareComAndroidSupportAnimatedVectorDrawable2340Library
  :app:prepareComAndroidSupportAppcompatV72340Library
  :app:prepareComAndroidSupportSupportV42340Library
  :app:prepareComAndroidSupportSupportVectorDrawable2340Library
  :app:prepareDebugDependencies
  :app:compileDebugAidl
  :app:compileDebugRenderscript
  :app:generateDebugBuildConfig
  :app:mergeDebugShaders
  :app:compileDebugShaders
  :app:generateDebugAssets
  :app:mergeDebugAssets
  :app:generateDebugResValues UP-TO-DATE
  :app:generateDebugResources
  :app:mergeDebugResources
  :app:processDebugManifest
  :app:processDebugResources
  :app:generateDebugSources
  :app:preDebugUnitTestBuild UP-TO-DATE
  :app:prepareDebugUnitTestDependencies
  :app:mockableAndroidJar UP-TO-DATE
  :app:preDebugAndroidTestBuild UP-TO-DATE
  :app:prepareDebugAndroidTestDependencies
  :app:compileDebugAndroidTestAidl
  :app:processDebugAndroidTestManifest
  :app:compileDebugAndroidTestRenderscript
  :app:generateDebugAndroidTestBuildConfig
  :app:mergeDebugAndroidTestShaders
  :app:compileDebugAndroidTestShaders
  :app:generateDebugAndroidTestAssets
  :app:mergeDebugAndroidTestAssets
  :app:generateDebugAndroidTestResValues UP-TO-DATE
  :app:generateDebugAndroidTestResources
  :app:mergeDebugAndroidTestResources
  :app:processDebugAndroidTestResources
  :app:generateDebugAndroidTestSources
  :app:incrementalDebugJavaCompilationSafeguard
  :app:compileDebugJavaWithJavac
  :app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
  :app:compileDebugNdk UP-TO-DATE
  :app:compileDebugSources
  :app:buildInfoDebugLoader
  :app:transformClassesWithExtractJarsForDebug
  :app:transformClassesWithInstantRunVerifierForDebug
  :app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
  :app:mergeDebugJniLibFolders
  :app:transformNative_libsWithMergeJniLibsForDebug
  :app:processDebugJavaRes UP-TO-DATE
  :app:transformResourcesWithMergeJavaResForDebug
  :app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
  :app:transformClassesWithInstantRunForDebug
  :app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
  :app:incrementalDebugTasks
  :app:prePackageMarkerForDebug
  :app:fastDeployDebugExtractor
  :app:generateDebugInstantRunAppInfo
  :app:coldswapKickerDebug
  :app:transformClassesWithInstantRunSlicerForDebug
  :app:transformClassesWithDexForDebug
  To run dex in process, the Gradle daemon needs a larger heap.
  It currently has approximately 910 MB.
  For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
  To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
  For more information see https://docs.gradle.org/current/userguide/build_environment.html
  Error:java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
  Error:  at java.lang.ClassLoader.defineClass1(Native Method)
  Error:java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
  Error:  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
  Error:  at java.lang.ClassLoader.defineClass1(Native Method)
  Error:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  Error:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  Error:  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  Error:  at java.security.AccessController.doPrivileged(Native Method)
  Error:  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  Error:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  Error:  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  Error:Exception in thread "main" 
  Error:  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
  Error:java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
  Error:  at java.lang.ClassLoader.defineClass1(Native Method)
  Error:  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
  Error:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  Error:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  Error:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  Error:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  Error:  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  Error:java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
  Error:  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  Error:  at java.lang.ClassLoader.defineClass1(Native Method)
  Error:  at java.security.AccessController.doPrivileged(Native Method)
  Error:  at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
  :app:transformClassesWithDexForDebug FAILED
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  Error:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  Error:  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  Error:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  Error:  at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  Error:  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  Error:  at java.security.AccessController.doPrivileged(Native Method)
  Error:  at java.security.AccessController.doPrivileged(Native Method)
  Error:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  Error:  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  Error:  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  Error:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  FAILURE: Build failed with an exception.
  Error:  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  Error:Exception in thread "main" 
  * What went wrong:
  Error:  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  Error:Exception in thread "main" 
  Error:  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  Error:  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  Error:  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  Error:Exception in thread "main" 
  Execution failed for task ':app:transformClassesWithDexForDebug'.
  &gt; com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  Information:BUILD FAILED
  Information:Total time: 4.702 secs
  Information:59 errors
  Information:0 warnings
  Information:See complete output in console
  </code></pre>
  
  <p>I don't know what I am doing wrong.  Thank you for your answers.</p>