Vlusion
Vlusion

Reputation: 79

Android Studio - App crash when using intent parameter

I have a function that 'crafts' products using two String parameters. This is working fine when I put in hard coded strings like 'Wheel' & 'Car'. But it makes my application crash if I try to put in the exact same strings but then provided by an intent.

I already tried to give in variable into the intent instead of a hard coded string. That did not work either. Here is some part of the code. EDIT: Error log now included

    productLeft = getIntent().getStringExtra("PRODUCT LEFT");
    productRight = getIntent().getStringExtra("PRODUCT RIGHT");

    public void craft(String product1, String product2) {
    String[][] Products = factory.getProductList();

    int i = 0;
    while (finalProduct == "") {
        int j;
        for(j = 0; j < 3; j++){
            if (product1 == Products[i][0] || product2 == Products[i][0]) {
                if (product1 == Products[i][1] || product2 == Products[i][1]){
                    finalProduct = Products[i][2];
                }
            }
            i++;
        }
    }
}

enter image description here

Upvotes: 0

Views: 94

Answers (1)

Bran
Bran

Reputation: 71

Problem is with the array index obviously. The array has only four elements and you are fetching index 4, probably in for loop with i variable. But then again I also do not see the role of j in that loop, can't tell without other parts of code.

Upvotes: 1

Related Questions