My app crashes every time I run this code

0

I'm trying to make a slot machine and everything is fine until I added some of this code that will calculate bets. I have $1 and a $5 bet button which will automatically deduct from the players bank roll when the button is clicked. Somehow, my app crashes when I run it. Here is the code. Can somebody point out to me if I miss out on something? It will be very helpful. Thanks.

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);

        }
    });

}

Here is my 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)
android
eclipse
asked on Stack Overflow Mar 28, 2014 by m.lacabe • edited Mar 28, 2014 by m.lacabe

1 Answer

1

Try this..

Change your code this bankRoll.setText(uBet); to bankRoll.setText(""+uBet); like below in ClickListener

betOne.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        uBet = uBet - BETONE;
        userBet.setText("Your Bet: " + BETONE);
        bankRoll.setText(""+uBet);

    }
});
answered on Stack Overflow Mar 28, 2014 by Hariharan

User contributions licensed under CC BY-SA 3.0