0

Whats the problem with this code?

package com.evorlor.samplecode;

import android.app.Activity;

public class MotionEvent extends Activity {

    public boolean onTouchEvent(MotionEvent me) {
        int i = me.getAction();

        switch (i) {

        case MotionEvent.ACTION_DOWN:
            // When your finger touches the screen

            break;

        case MotionEvent.ACTION_UP:
            // When your finger stop touching the screen

            break;

        case MotionEvent.ACTION_MOVE:
            // When your finger moves around the screen

            break;
        }

        return false;
    }

}

It is giving the error:

The method getAction() is undefined for the type MotionEvent on the .getAction(). It will not let me import:

import android.view.MotionEvent;

As far as I can tell, it is the same as this working code (aside from it not letting me import the import android.view.MotionEvent;):

package com.evorlor.counter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class Counter extends Activity {

    private static int count = 0;
    private static int hiCount = 0;
    private static boolean capCount = false;
    public static boolean resetCount = false;
    public static boolean askReset = false;

    public boolean onTouchEvent(MotionEvent me) {
        if (me.getAction() == MotionEvent.ACTION_UP) {
            count++;
        }

        onCreate(null);

        return false;
    }
}

Thanks for the help!

Evorlor
  • 7,263
  • 17
  • 70
  • 141

2 Answers2

4

Rename your Activity to something else, it is conflicting with the actual MotionEvent Class it needs.

A--C
  • 36,351
  • 10
  • 106
  • 92
1

The class name you defined hides android.view.MotionEvent

public class MotionEvent

Just change the class name, your problem will be solved

Qiang Jin
  • 4,427
  • 19
  • 16