我试图制作老虎机,一切都很好,直到我添加了一些计算赌注的代码。我有1美元和5美元的下注按钮,当点击按钮时,它会自动从玩家银行存款中扣除。不知何故,当我运行它时,我的应用程序崩溃了。这是代码。如果我错过了某些东西,有人可以向我指出吗?这将非常有帮助。感谢。
ViewFlipper slotOne, slotTwo, slotThree, spinStop;
Button spin, stop, betOne, betFive;
TextView userBet, bankRoll;
final int BETONE = 1, BETFIVE = 5;
int uBet = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_main);
this.initSpin();
this.initStop();
this.placeBet1();
//this.placeBet5();
}
private void placeBet1() {
betOne = (Button) findViewById (R.id.bet1);
userBet = (TextView) findViewById (R.id.userBet);
bankRoll = (TextView) findViewById (R.id.bankroll);
betOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uBet = uBet - BETONE;
userBet.setText("Your Bet: " + BETONE);
bankRoll.setText(uBet);
}
});
}
这是我的logcat:
03-27 18:17:46.268: I/Process(22207): Sending signal. PID: 22207 SIG: 9
03-27 18:17:51.598: D/dalvikvm(22449): GC_FOR_ALLOC freed 92K, 7% free 9481K/10179K, paused 27ms, total 27ms
03-27 18:17:51.603: I/dalvikvm-heap(22449): Grow heap (frag case) to 10.382MB for 600016-byte allocation
03-27 18:17:51.633: D/dalvikvm(22449): GC_CONCURRENT freed 1K, 7% free 10066K/10823K, paused 12ms+2ms, total 33ms
03-27 18:17:51.748: D/libEGL(22449): loaded /system/lib/egl/libEGL_mali.so
03-27 18:17:51.758: D/libEGL(22449): loaded /system/lib/egl/libGLESv1_CM_mali.so
03-27 18:17:51.758: D/libEGL(22449): loaded /system/lib/egl/libGLESv2_mali.so
03-27 18:17:51.763: D/(22449): Device driver API match
03-27 18:17:51.763: D/(22449): Device driver API version: 10
03-27 18:17:51.763: D/(22449): User space API version: 10
03-27 18:17:51.763: D/(22449): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
03-27 18:17:51.783: D/OpenGLRenderer(22449): Enabling debug mode 0
03-27 18:17:58.928: D/dalvikvm(22449): GC_FOR_ALLOC freed 618K, 13% free 9686K/11015K, paused 17ms, total 17ms
03-27 18:17:58.928: I/dalvikvm-heap(22449): Grow heap (frag case) to 10.583MB for 600016-byte allocation
03-27 18:17:58.973: D/dalvikvm(22449): GC_CONCURRENT freed <1K, 7% free 10272K/11015K, paused 12ms+1ms, total 42ms
03-27 18:17:59.058: D/dalvikvm(22449): GC_CONCURRENT freed 779K, 13% free 10024K/11399K, paused 12ms+11ms, total 35ms
03-27 18:18:00.148: W/ResourceType(22449): No package identifier when getting value for resource number 0x00000063
03-27 18:18:00.148: D/AndroidRuntime(22449): Shutting down VM
03-27 18:18:00.148: W/dalvikvm(22449): threadid=1: thread exiting with uncaught exception (group=0x416122a0)
03-27 18:18:00.168: E/AndroidRuntime(22449): FATAL EXCEPTION: main
03-27 18:18:00.168: E/AndroidRuntime(22449): android.content.res.Resources$NotFoundException: String resource ID #0x63
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.content.res.Resources.getText(Resources.java:513)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.widget.TextView.setText(TextView.java:3849)
03-27 18:18:00.168: E/AndroidRuntime(22449): at com.ics136leeward.slotmachine.GameMainActivity$1.onClick(GameMainActivity.java:41)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.view.View.performClick(View.java:4261)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.view.View$PerformClick.run(View.java:17414)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.os.Handler.handleCallback(Handler.java:615)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.os.Handler.dispatchMessage(Handler.java:92)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.os.Looper.loop(Looper.java:137)
03-27 18:18:00.168: E/AndroidRuntime(22449): at android.app.ActivityThread.main(ActivityThread.java:4938)
03-27 18:18:00.168: E/AndroidRuntime(22449): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 18:18:00.168: E/AndroidRuntime(22449): at java.lang.reflect.Method.invoke(Method.java:511)
03-27 18:18:00.168: E/AndroidRuntime(22449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-27 18:18:00.168: E/AndroidRuntime(22449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-27 18:18:00.168: E/AndroidRuntime(22449): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
试试这个..
将您的代码bankRoll.setText(uBet);
改为bankRoll.setText(""+uBet);
,如下所示 ClickListener
betOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uBet = uBet - BETONE;
userBet.setText("Your Bet: " + BETONE);
bankRoll.setText(""+uBet);
}
});