Home>

[I want to ask]
I'm creating a slot game in android studio
I would like to judge the picture when the bingo occurred.
I get an error with the following source code
I looked at the logcat and looked it up, but I couldn't find the cause.
If i have any details, please teach with a commentary.

[Source code]
(Import etc. are described with some labor saving)

package sample.example.droidslot4;
import java.util.Random;
public class DroidSlotActivity extends AppCompatActivity {
    int droidSide1 = -1;
    int droidSide2 = -1;
    int droidSide3 = -1;
    int droidSide4 = -1;
    int droidSide5 = -1;
    int droidSide6 = -1;
    int droidSide7 = -1;
    int droidSide8 = -1;
    int droidSide9 = -1;
    int cnt = 0;
    Button retryButton;
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_droid_slot);
        final ImageView droidImage1 = (ImageView) this.findViewById (R.id.droidimageid1);
        final ImageView droidImage2 = (ImageView) this.findViewById (R.id.droidimageid2);
        final ImageView droidImage3 = (ImageView) this.findViewById (R.id.droidimageid3);
        final ImageView droidImage4 = (ImageView) this.findViewById (R.id.droidimageid4);
        final ImageView droidImage5 = (ImageView) this.findViewById (R.id.droidimageid5);
        final ImageView droidImage6 = (ImageView) this.findViewById (R.id.droidimageid6);
        final ImageView droidImage7 = (ImageView) this.findViewById (R.id.droidimageid7);
        final ImageView droidImage8 = (ImageView) this.findViewById (R.id.droidimageid8);
        final ImageView droidImage9 = (ImageView) this.findViewById (R.id.droidimageid9);
        final TextView chip = (TextView) this.findViewById (R.id.chip);
        final TextView bet = (TextView) this.findViewById (R.id.bet);
        final Random r = new Random ();
        final Button b1 = (Button) this.findViewById (R.id.slotbutton1);
        final Button b2 = (Button) this.findViewById (R.id.slotbutton2);
        final Button b3 = (Button) this.findViewById (R.id.slotbutton3);
        retryButton = (Button) this.findViewById (R.id.retrybutton);
        retryButton.setVisibility (View.INVISIBLE);
        b1.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick (View v) {
                droidSide1 = r.nextInt (8);// Setting the left vertical column 123
                droidSide4 = r.nextInt (8);// 456
                droidSide7 = r.nextInt (8);// 789
                droidImage1.setImageResource (getID (droidSide1));
                droidImage4.setImageResource (getID (droidSide4));
                droidImage7.setImageResource (getID (droidSide7));
                b1.setEnabled (false);
                if (b1.isEnabled () == false&&b2.isEnabled () == false&&b3.isEnabled () == false) {judge ();
                }
            }
        });
// Same as b2 and b3 below
    private void judge () {
        int BINGO [] [];
        int chara [];
        int flag = -1;
        int j = 0;
        int point = 1;
        BINGO = new int [3] [3];// Place images on 9 panels of 3x3 (random)
        BINGO [0] [0] = droidSide1;
        BINGO [0] [1] = droidSide2;
        BINGO [0] [2] = droidSide3;
        BINGO [1] [0] = droidSide4;
        BINGO [1] [1] = droidSide5;
        BINGO [1] [2] = droidSide6;
        BINGO [2] [0] = droidSide7;
        BINGO [2] [1] = droidSide8;
        BINGO [2] [2] = droidSide9;
        chara = new int [8];
        for (int i = 0;i<chara.length;i ++) {
            chara [i] = getID (j);// Call the getID method and assign 0 to 7 images to the chara array
            j ++;
        }
        // x = horizontal
        // y = vertical
        for (int x = 0;x<BINGO.length;x ++) {// I want to see vertically
            for (int y = 0;y<BINGO.length;y ++) {
                if (BINGO [y] [x]! = BINGO [y + 1] [x]) {
                    break;
                } else if (flag>= BINGO.length --2) {
                    cnt ++;
                    if (BINGO [y + 1] [x] == chara [0]) {
                        point * = 50;
                    } else if (BINGO [y + 1] [x] == chara [1]) {
                        point * = 1000;
                    } else if (BINGO [y + 1] [x] == chara [2]) {
                        point * = 500;
                    } else if (BINGO [y + 1] [x] == chara [3]) {
                        point * = 10;
                    } else if (BINGO [y + 1] [x] == chara [4]) {
                        point * = 30;
                    } else if (BINGO [y + 1] [x] == chara [5]) {
                        point * = 25;
                    } else if (BINGO [y + 1] [x] == chara [6]) {
                        point * = 20;
                    } else if (BINGO [y + 1] [x] == chara [7]) {
                        point * = 100;
                    }
                    break;
                } else {
                    flag = y + 1;}
            }
            flag = -1;
        }
// Same for the side
        if (droidSide1 == droidSide5&&droidSide1 == droidSide9&&droidSide1! = -1&&droidSide5! = -1&&droidSide9! = -1) {
            cnt ++;
            if (droidSide1 == chara [0]) {
                point * = 50;
            } else if (droidSide1 == chara [1]) {
                point * = 1000;
            } else if (droidSide1 == chara [2]) {
                point * = 500;
            } else if (droidSide1 == chara [3]) {
                point * = 10;
            } else if (droidSide1 == chara [4]) {
                point * = 30;
            } else if (droidSide1 == chara [5]) {
                point * = 25;
            } else if (droidSide1 == chara [6]) {
                point * = 20;
            } else if (droidSide1 == chara [7]) {
                point * = 100;
            }
        }
        if (droidSide3 == droidSide5&&droidSide3 == droidSide7&&droidSide3! = -1&&droidSide5! = -1&&droidSide7! = -1) {
            cnt ++;
            if (droidSide3 == chara [0]) {
                point * = 50;
            } else if (droidSide3 == chara [1]) {
                point * = 1000;
            } else if (droidSide3 == chara [2]) {
                point * = 500;
            } else if (droidSide3 == chara [3]) {
                point * = 10;
            } else if (droidSide3 == chara [4]) {
                point * = 30;
            } else if (droidSide3 == chara [5]) {
                point * = 25;
            } else if (droidSide3 == chara [6]) {
                point * = 20;
            } else if (droidSide3 == chara [7]) {
                point * = 100;
            }
        }
        Toast t = Toast.makeText (getApplicationContext (), cnt + "BINGO!", Toast.LENGTH_SHORT);
        t.setGravity (Gravity.CENTER, 0,500);
        t.show ();
        Toast z = Toast.makeText (getApplicationContext (), point, Toast.LENGTH_SHORT);
        z.setGravity (Gravity.CENTER, 0,550);
        z.show ();
        cnt = 0;
        retryButton.setVisibility (View.VISIBLE);
    }private int getID (int nintendo) {
        int id;
        switch (nintendo) {
            case 0:
                id = R.drawable.kiler;
                break;
            case 1:
                id = R.drawable.star;
                break;
            case 2:
                id = R.drawable.starback;
                break;
            case 3:
                id = R.drawable.banana;
                break;
            case 4:
                id = R.drawable.bkoura;
                break;
            case 5:
                id = R.drawable.rkoura;
                break;
            case 6:
                id = R.drawable.gkoura;
                break;
            case 7:
                id = R.drawable.mash;
                break;
            default: default:
                id = R.drawable.black;
                break;
        }
        return id;
    }
}

[error contents]
10-02 07: 41: 40.004 3304-3322/sample.example.droidslot4 E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2549820
10-02 07: 41: 41.853 3304-3304/sample.example.droidslot4 E/AndroidRuntime: FATAL EXCEPTION: main
Process: sample.example.droidslot4, PID: 3304
android.content.res.Resources $NotFoundException: String resource ID # 0x1
at android.content.res.Resources.getText (Resources.java:312)
at android.widget.Toast.makeText (Toast.java:286)
at sample.example.droidslot4.DroidSlotActivity.judge (DroidSlotActivity.java:262)
at sample.example.droidslot4.DroidSlotActivity.access $100 (DroidSlotActivity.java:15)
at sample.example.droidslot4.DroidSlotActivity $3.onClick (DroidSlotActivity.java:104)
at android.view.View.performClick (View.java:5198)
at com.google.android.material.button.MaterialButton.performClick (MaterialButton.java:992)
at android.view.View $PerformClick.run (View.java:21147)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

  • Answer # 1

    android.content.res.Resources $NotFoundException: String resource ID # 0x1

    From the display, you can see that there is a problem with the resource ID of String,

    at sample.example.droidslot4.DroidSlotActivity.judge (DroidSlotActivity.java:262)

    Line 262 of DroidSlotActivity.javajudge ()You can see that there is a problem in the method.

    I don't know from the source provided where line 262 of DroidSlotActivity.java is, but it's probably the following line that's wrong.

          Toast z = Toast.makeText (getApplicationContext (), point, Toast.LENGTH_SHORT);

    point is an int type variable,makeText ()If you give an int type value to the second argument ofR.string.hogeIt considers it as a resource ID like this and tries to process it. Since point is just a number, if you execute this as it is, the application will fall as if it was given a resource ID that does not exist.

          Toast z = Toast.makeText (getApplicationContext (), String.valueOf (point), Toast.LENGTH_SHORT);


    I think it can be improved by converting point to a character string like this.