Android的 - 活动不能被解析为一个类型 [英] Android - Activity cannot be resolved to a type
问题描述
我是新来的Android和使用Eclipse(背景在基本的Java和Netbeans)
I'm new to android, and using Eclipse (Background in basic java and Netbeans)
我只是下面的一个基本的游戏土特:
I'm just following a basic game tute on:
和具有以下错误:
活动不能被解析为一个类型。
Activity cannot be resolved to a type.
((Activity)getContext()).finish();
以上是code是上有错误,我已经在谷歌试图看这里也将没有真正的帮助,或者至少是我的理解。
Above is the code it is having an error on, I've tried look on Google and here also will no real help, or at least that I understood.
下面是全班同学:
package Sketchy.Game.WarSoNawty;
import android.util.Log;
import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainGamePanel extends SurfaceView implements
SurfaceHolder.Callback {
private static final String TAG = MainGamePanel.class.getSimpleName();
private MainThread thread;
public MainGamePanel(Context context) {
super(context);
//adding the callback (this) to the surface holder to intercept events
getHolder().addCallback(this);
//create game loop
thread = new MainThread(getHolder(), this);
//make the GamePanel focusable so it can handle events
setFocusable(true);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
while (retry) {
try {
thread.join();
retry = false;
}
catch (InterruptedException e) {
//try again shutting down the thread
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if(event.getY() > getHeight() - 50) {
thread.setRunning(false);
((Activity)getContext()).finish();
}
else {
Log.d(TAG, "Coords: x=" +event.getX() + ",y=" + event.getY());
}
}
return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas) {
}
}
我读过,可能是我的意思清单是不正确的,下面是该XML。
I've read that is could mean my Manifest isn't right, below is the XML for that.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Sketchy.Game.WarSoNawty"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".WarSoNawty"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在此先感谢您的帮助!
Thanks in advance for any help!
推荐答案
好像你还没有导入活动
类。该行添加到您的import语句(略高于类
声明):
Seems like you haven't imported the Activity
class. Add this line to your import statements (just above the class
declaration) :
import android.app.Activity;
这篇关于Android的 - 活动不能被解析为一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!