管理 android 游戏中的活动
Managing activities in android game
正在 android 创建游戏。
我有一个带有自定义视图图形的游戏 activity。
我想在角色死亡时午餐 GameOver activity,但应用程序崩溃
(线上:startActivity(new Intent("android.intent.action.GAMEOVER"))。
我尝试创建方法 gameOver() 并在其中启动 activity。
public class Game extends Activity {
static Graphics graphics;
//...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
graphics = new Graphics(this);
setContentView(graphics);
//...
}
// TODO
void gameOver() {
// Game crashes here
startActivity(new Intent("android.intent.action.GAMEOVER"));
}
}
然后我尝试通过创建游戏对象从我的自定义视图中运行此方法:-
public class Graphics extends View {
Game game;
private boolean somethingHappened;
//...
public Graphics(Context context) {
super(context);
game = new Game();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (somethingHappened) {
theHeroDies();
}
invalidate();
}
void theHeroDies() {
game.gameOver();
}
}
GameOver activity 如果我 运行 使用菜单按钮可以完美运行。
清单在这里:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Game"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ResultActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.RESULT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AboutActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".GameOverActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.GAMEOVER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
日志在这里:
05-10 12:33:13.619: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.621: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:13.779: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.781: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:13.800: I/View(31179): Touch down dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=301.44177, y[0]=450.5307, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289301, downTime=291289301, deviceId=3, source=0x1002 }
05-10 12:33:13.985: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.987: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.001: I/View(31179): Touch up dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=301.44177, y[0]=450.5307, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289389, downTime=291289301, deviceId=3, source=0x1002 }
05-10 12:33:14.192: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.193: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.209: I/View(31179): Touch down dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=296.45102, y[0]=407.57544, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289614, downTime=291289614, deviceId=3, source=0x1002 }
05-10 12:33:14.227: I/View(31179): Touch up dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=296.45102, y[0]=407.57544, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289692, downTime=291289614, deviceId=3, source=0x1002 }
05-10 12:33:14.392: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.394: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.552: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.553: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.711: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.713: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.866: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.867: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.030: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.031: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.173: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.176: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.345: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.348: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.525: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.527: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.712: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.715: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.907: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.910: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.090: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.095: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.256: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.258: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.431: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.434: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.601: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.604: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.774: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.777: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.958: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.961: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.126: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.129: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.292: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.295: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.470: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.473: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.657: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.659: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.828: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.831: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.021: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.023: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.191: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.196: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.371: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.374: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.543: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.548: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.730: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.733: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.943: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.946: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.124: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.127: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.293: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.296: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.467: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.470: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.650: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.653: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.820: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.823: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.990: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.993: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.168: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.171: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.339: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.343: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.526: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.529: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.695: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.697: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.880: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.882: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.058: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.061: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.239: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.241: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.433: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.435: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.611: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.614: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.788: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.790: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.968: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.971: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.150: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.153: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.340: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.344: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.523: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.526: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.711: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.714: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.880: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.882: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.073: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.076: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.257: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.260: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.350: D/dalvikvm(31179): GC_FOR_ALLOC freed 3097K (5748), 17% free 16475K/19616K, paused 36ms, total 50ms
05-10 12:33:23.500: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.504: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.672: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.676: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.851: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.854: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.621: D/View(31179): [ANR Warning]onDraw time too long, this =com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}time =746
05-10 12:33:24.622: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.625: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.766: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.768: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.930: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.933: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.080: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.083: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.252: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.255: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.411: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.414: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.568: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.571: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.739: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.742: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.892: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.895: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:34:22.685: D/AndroidRuntime(31179): Shutting down VM
05-10 12:34:22.685: W/dalvikvm(31179): threadid=1: thread exiting with uncaught exception (group=0x41d2ecf8)
05-10 12:34:22.686: W/dalvikvm(31179): threadid=1: uncaught exception occurred
05-10 12:34:22.688: W/System.err(31179): java.lang.NullPointerException
05-10 12:34:22.700: W/System.err(31179): at android.app.Activity.startActivityForResult(Activity.java:3483)
05-10 12:34:22.703: W/System.err(31179): at android.app.Activity.startActivityForResult(Activity.java:3435)
05-10 12:34:22.708: W/System.err(31179): at android.app.Activity.startActivity(Activity.java:3686)
05-10 12:34:22.714: W/System.err(31179): at android.app.Activity.startActivity(Activity.java:3654)
05-10 12:34:22.715: W/System.err(31179): at com.example.emi.Game.gameOver(Game.java:53)
05-10 12:34:22.717: W/System.err(31179): at com.example.emi.Graphics.die(Graphics.java:515)
05-10 12:34:22.719: W/System.err(31179): at com.example.emi.Graphics.onDraw(Graphics.java:289)
05-10 12:34:22.720: W/System.err(31179): at android.view.View.draw(View.java:14728)
05-10 12:34:22.722: W/System.err(31179): at android.view.View.getDisplayList(View.java:13588)
05-10 12:34:22.724: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.725: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.727: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.729: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.730: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.732: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.734: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.735: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.737: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.739: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.741: W/System.err(31179): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1627)
05-10 12:34:22.742: W/System.err(31179): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1506)
05-10 12:34:22.745: W/System.err(31179): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2722)
05-10 12:34:22.751: W/System.err(31179): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2587)
05-10 12:34:22.758: W/System.err(31179): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2210)
05-10 12:34:22.760: W/System.err(31179): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
05-10 12:34:22.761: W/System.err(31179): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
05-10 12:34:22.763: W/System.err(31179): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
05-10 12:34:22.770: W/System.err(31179): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
05-10 12:34:22.772: W/System.err(31179): at android.view.Choreographer.doFrame(Choreographer.java:560)
05-10 12:34:22.774: W/System.err(31179): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
05-10 12:34:22.776: W/System.err(31179): at android.os.Handler.handleCallback(Handler.java:808)
05-10 12:34:22.779: W/System.err(31179): at android.os.Handler.dispatchMessage(Handler.java:103)
05-10 12:34:22.781: W/System.err(31179): at android.os.Looper.loop(Looper.java:193)
05-10 12:34:22.782: W/System.err(31179): at android.app.ActivityThread.main(ActivityThread.java:5333)
05-10 12:34:22.783: W/System.err(31179): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:34:22.785: W/System.err(31179): at java.lang.reflect.Method.invoke(Method.java:515)
05-10 12:34:22.786: W/System.err(31179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
05-10 12:34:22.787: W/System.err(31179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
05-10 12:34:22.789: W/System.err(31179): at dalvik.system.NativeStart.main(Native Method)
05-10 12:34:22.789: W/dalvikvm(31179): threadid=1: calling UncaughtExceptionHandler
05-10 12:34:22.832: E/AndroidRuntime(31179): FATAL EXCEPTION: main
05-10 12:34:22.832: E/AndroidRuntime(31179): Process: com.example.emi, PID: 31179
05-10 12:34:22.832: E/AndroidRuntime(31179): java.lang.NullPointerException
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivityForResult(Activity.java:3483)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivityForResult(Activity.java:3435)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivity(Activity.java:3686)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivity(Activity.java:3654)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Game.gameOver(Game.java:53)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Graphics.die(Graphics.java:515)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Graphics.onDraw(Graphics.java:289)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.draw(View.java:14728)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13588)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1627)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1506)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2722)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2587)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2210)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer.doFrame(Choreographer.java:560)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Handler.handleCallback(Handler.java:808)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Handler.dispatchMessage(Handler.java:103)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Looper.loop(Looper.java:193)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.ActivityThread.main(ActivityThread.java:5333)
05-10 12:34:22.832: E/AndroidRuntime(31179): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:34:22.832: E/AndroidRuntime(31179): at java.lang.reflect.Method.invoke(Method.java:515)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
05-10 12:34:22.832: E/AndroidRuntime(31179): at dalvik.system.NativeStart.main(Native Method)
您可能希望使用上下文从视图启动 activity。
您可以尝试更改此设置:
void theHeroDies() {
game.gameOver();
}
对此:
void theHeroDies() {
getContext().startActivity(new Intent("android.intent.action.GAMEOVER"));
}
正在 android 创建游戏。
我有一个带有自定义视图图形的游戏 activity。
我想在角色死亡时午餐 GameOver activity,但应用程序崩溃
(线上:startActivity(new Intent("android.intent.action.GAMEOVER"))。
我尝试创建方法 gameOver() 并在其中启动 activity。
public class Game extends Activity {
static Graphics graphics;
//...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
graphics = new Graphics(this);
setContentView(graphics);
//...
}
// TODO
void gameOver() {
// Game crashes here
startActivity(new Intent("android.intent.action.GAMEOVER"));
}
}
然后我尝试通过创建游戏对象从我的自定义视图中运行此方法:-
public class Graphics extends View {
Game game;
private boolean somethingHappened;
//...
public Graphics(Context context) {
super(context);
game = new Game();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (somethingHappened) {
theHeroDies();
}
invalidate();
}
void theHeroDies() {
game.gameOver();
}
}
GameOver activity 如果我 运行 使用菜单按钮可以完美运行。
清单在这里:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Game"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ResultActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.RESULT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AboutActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".GameOverActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.GAMEOVER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
日志在这里:
05-10 12:33:13.619: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.621: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:13.779: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.781: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:13.800: I/View(31179): Touch down dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=301.44177, y[0]=450.5307, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289301, downTime=291289301, deviceId=3, source=0x1002 }
05-10 12:33:13.985: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:13.987: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.001: I/View(31179): Touch up dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=301.44177, y[0]=450.5307, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289389, downTime=291289301, deviceId=3, source=0x1002 }
05-10 12:33:14.192: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.193: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.209: I/View(31179): Touch down dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=296.45102, y[0]=407.57544, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289614, downTime=291289614, deviceId=3, source=0x1002 }
05-10 12:33:14.227: I/View(31179): Touch up dispatch to com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=296.45102, y[0]=407.57544, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=291289692, downTime=291289614, deviceId=3, source=0x1002 }
05-10 12:33:14.392: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.394: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.552: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.553: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.711: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.713: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:14.866: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:14.867: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.030: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.031: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.173: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.176: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.345: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.348: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.525: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.527: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.712: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.715: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:15.907: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:15.910: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.090: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.095: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.256: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.258: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.431: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.434: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.601: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.604: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.774: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.777: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:16.958: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:16.961: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.126: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.129: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.292: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.295: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.470: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.473: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.657: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.659: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:17.828: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:17.831: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.021: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.023: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.191: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.196: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.371: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.374: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.543: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.548: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.730: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.733: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:18.943: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:18.946: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.124: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.127: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.293: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.296: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.467: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.470: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.650: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.653: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.820: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.823: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:19.990: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:19.993: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.168: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.171: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.339: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.343: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.526: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.529: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.695: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.697: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:20.880: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:20.882: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.058: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.061: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.239: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.241: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.433: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.435: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.611: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.614: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.788: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.790: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:21.968: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:21.971: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.150: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.153: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.340: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.344: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.523: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.526: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.711: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.714: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:22.880: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:22.882: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.073: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.076: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.257: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.260: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.350: D/dalvikvm(31179): GC_FOR_ALLOC freed 3097K (5748), 17% free 16475K/19616K, paused 36ms, total 50ms
05-10 12:33:23.500: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.504: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.672: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.676: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:23.851: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:23.854: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.621: D/View(31179): [ANR Warning]onDraw time too long, this =com.example.emi.Graphics{423dc3c8 V.ED.... ......ID 0,0-540,960}time =746
05-10 12:33:24.622: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.625: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.766: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.768: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:24.930: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:24.933: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.080: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.083: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.252: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.255: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.411: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.414: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.568: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.571: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.739: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.742: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:33:25.892: D/OpenGLRenderer(31179): prepareDirty (0.00, 0.00, 540.00, 960.00) opaque 1 <0x61ced4a0>
05-10 12:33:25.895: D/OpenGLRenderer(31179): finish <0x61ced4a0>
05-10 12:34:22.685: D/AndroidRuntime(31179): Shutting down VM
05-10 12:34:22.685: W/dalvikvm(31179): threadid=1: thread exiting with uncaught exception (group=0x41d2ecf8)
05-10 12:34:22.686: W/dalvikvm(31179): threadid=1: uncaught exception occurred
05-10 12:34:22.688: W/System.err(31179): java.lang.NullPointerException
05-10 12:34:22.700: W/System.err(31179): at android.app.Activity.startActivityForResult(Activity.java:3483)
05-10 12:34:22.703: W/System.err(31179): at android.app.Activity.startActivityForResult(Activity.java:3435)
05-10 12:34:22.708: W/System.err(31179): at android.app.Activity.startActivity(Activity.java:3686)
05-10 12:34:22.714: W/System.err(31179): at android.app.Activity.startActivity(Activity.java:3654)
05-10 12:34:22.715: W/System.err(31179): at com.example.emi.Game.gameOver(Game.java:53)
05-10 12:34:22.717: W/System.err(31179): at com.example.emi.Graphics.die(Graphics.java:515)
05-10 12:34:22.719: W/System.err(31179): at com.example.emi.Graphics.onDraw(Graphics.java:289)
05-10 12:34:22.720: W/System.err(31179): at android.view.View.draw(View.java:14728)
05-10 12:34:22.722: W/System.err(31179): at android.view.View.getDisplayList(View.java:13588)
05-10 12:34:22.724: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.725: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.727: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.729: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.730: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.732: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.734: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.735: W/System.err(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.737: W/System.err(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.739: W/System.err(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.741: W/System.err(31179): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1627)
05-10 12:34:22.742: W/System.err(31179): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1506)
05-10 12:34:22.745: W/System.err(31179): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2722)
05-10 12:34:22.751: W/System.err(31179): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2587)
05-10 12:34:22.758: W/System.err(31179): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2210)
05-10 12:34:22.760: W/System.err(31179): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
05-10 12:34:22.761: W/System.err(31179): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
05-10 12:34:22.763: W/System.err(31179): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
05-10 12:34:22.770: W/System.err(31179): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
05-10 12:34:22.772: W/System.err(31179): at android.view.Choreographer.doFrame(Choreographer.java:560)
05-10 12:34:22.774: W/System.err(31179): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
05-10 12:34:22.776: W/System.err(31179): at android.os.Handler.handleCallback(Handler.java:808)
05-10 12:34:22.779: W/System.err(31179): at android.os.Handler.dispatchMessage(Handler.java:103)
05-10 12:34:22.781: W/System.err(31179): at android.os.Looper.loop(Looper.java:193)
05-10 12:34:22.782: W/System.err(31179): at android.app.ActivityThread.main(ActivityThread.java:5333)
05-10 12:34:22.783: W/System.err(31179): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:34:22.785: W/System.err(31179): at java.lang.reflect.Method.invoke(Method.java:515)
05-10 12:34:22.786: W/System.err(31179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
05-10 12:34:22.787: W/System.err(31179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
05-10 12:34:22.789: W/System.err(31179): at dalvik.system.NativeStart.main(Native Method)
05-10 12:34:22.789: W/dalvikvm(31179): threadid=1: calling UncaughtExceptionHandler
05-10 12:34:22.832: E/AndroidRuntime(31179): FATAL EXCEPTION: main
05-10 12:34:22.832: E/AndroidRuntime(31179): Process: com.example.emi, PID: 31179
05-10 12:34:22.832: E/AndroidRuntime(31179): java.lang.NullPointerException
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivityForResult(Activity.java:3483)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivityForResult(Activity.java:3435)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivity(Activity.java:3686)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.Activity.startActivity(Activity.java:3654)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Game.gameOver(Game.java:53)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Graphics.die(Graphics.java:515)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.example.emi.Graphics.onDraw(Graphics.java:289)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.draw(View.java:14728)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13588)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3226)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13509)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.View.getDisplayList(View.java:13635)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1627)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1506)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2722)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2587)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2210)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer.doFrame(Choreographer.java:560)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Handler.handleCallback(Handler.java:808)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Handler.dispatchMessage(Handler.java:103)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.os.Looper.loop(Looper.java:193)
05-10 12:34:22.832: E/AndroidRuntime(31179): at android.app.ActivityThread.main(ActivityThread.java:5333)
05-10 12:34:22.832: E/AndroidRuntime(31179): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 12:34:22.832: E/AndroidRuntime(31179): at java.lang.reflect.Method.invoke(Method.java:515)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
05-10 12:34:22.832: E/AndroidRuntime(31179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
05-10 12:34:22.832: E/AndroidRuntime(31179): at dalvik.system.NativeStart.main(Native Method)
您可能希望使用上下文从视图启动 activity。
您可以尝试更改此设置:
void theHeroDies() {
game.gameOver();
}
对此:
void theHeroDies() {
getContext().startActivity(new Intent("android.intent.action.GAMEOVER"));
}