I'm trying to add a button that can pause the threads that run my
game. It looks like I can basically copy paste the button example, but
it doesn't work.
public GameView(Context context, AttributeSet attributeSet) {
super(context);
getHolder().addCallback(this);
mainThread = new MainThread(getHolder(), this);
timerThread = new TimerThread();
final Button pauseButton = (Button)
findViewById(R.id.pauseButton);
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pauseGame();
}
});
}
It runs perfectly without the button object creation/onclicklistener
setting, but with it added it crashes. Am I doing something wrong?
Errors from LogCat:
08-25 19:22:18.126: ERROR/AndroidRuntime(951): FATAL EXCEPTION: main
08-25 19:22:18.126: ERROR/AndroidRuntime(951):
java.lang.IllegalStateException: Could not execute method of the
activity
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at android.view.View
$1.onClick(View.java:2072)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.View.performClick(View.java:2408)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at android.view.View
$PerformClick.run(View.java:8816)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.os.Handler.handleCallback(Handler.java:587)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.os.Handler.dispatchMessage(Handler.java:92)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.os.Looper.loop(Looper.java:123)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.app.ActivityThread.main(ActivityThread.java:4627)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Method.invokeNative(Native Method)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Method.invoke(Method.java:521)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
dalvik.system.NativeStart.main(Native Method)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): Caused by:
java.lang.reflect.InvocationTargetException
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
parachute.game.ParachuteActivity.newGame(ParachuteActivity.java:27)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Method.invokeNative(Native Method)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Method.invoke(Method.java:521)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at android.view.View
$1.onClick(View.java:2067)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): ... 11 more
08-25 19:22:18.126: ERROR/AndroidRuntime(951): Caused by:
android.view.InflateException: Binary XML file line #9: Error
inflating class parachute.game.GameView
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:
198)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.app.Activity.setContentView(Activity.java:1647)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): ... 15 more
08-25 19:22:18.126: ERROR/AndroidRuntime(951): Caused by:
java.lang.reflect.InvocationTargetException
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
parachute.game.GameView.<init>(GameView.java:46)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Constructor.constructNative(Native Method)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): at
android.view.LayoutInflater.createView(LayoutInflater.java:500)
08-25 19:22:18.126: ERROR/AndroidRuntime(951): ... 22 more
08-25 19:22:18.126: ERROR/AndroidRuntime(951): Caused by:
java.lang.NullPointerException
08-25 19:22:18.126: ERROR/AndroidRuntime(951): ... 26 more
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en