0

i got a Productclass stored in ArrayList myValues. I want to go trough each xth ( for example each 3th) element and have the user add some Integer values to that class.

In my for(...) he tells me: The left-hand side of an assignment must be a variable. I wonder if i messed up some of the .get(j) or if i have to synchronize my methods so that the size wont change ( there is no multi-threading but maybe thats why i get an error? ) or the solution is more simple.

Thx

public void prioPerProduct (){

    System.out.println("");
    System.out.println("Please enter storing and upgrading cost:");

    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    int storingCost = 0;
    int ruestCost = 0;
    int countRes = countRessources;
    int sizemyValues = myValues.size();
    for(int j = 0; j < sizemyValues; j = j+countRes){

        System.out.println("Please enter storingcost " + myValues.get(j).getProduct() +":" );
        try {
            storingCost = Integer.valueOf(br.readLine());
        } catch (NumberFormatException e) {
            System.out.println("No number entered");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("No number entered");
            e.printStackTrace();
        }

        System.out.println("Please enter upgradingcost " + myValues.get(j).getProduct() +":" );
        try {
            ruestCost = Integer.valueOf(br.readLine());
        } catch (NumberFormatException e) {
            System.out.println("No number entered");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("No number entered");
            e.printStackTrace();
        }

        myValues.get(j).setstoringCost(storingCost);
        myValues.get(j).setupgradingCost(ruestCost);


    }


}
2
  • Could you provide the complete stacktrace of the error ? Commented May 14, 2016 at 17:00
  • nvm, it works now, didnt change anything but suddenly it works ;) Commented May 14, 2016 at 17:07

2 Answers 2

1

The left-hand side of an assignment must be a variable is generally caused by something like this:

methodCall() = somvalue...

The left hand side must be a variable rather than a method call. Your code looks fine in this regard.
The code where you declare your model class and a full stack trace are more helpful.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the set method to change the value of an object inside of an ArrayList.

myValues.set(j,myValues.get().setstoringCost(storingCost));
myValues.set(j,myValues.get().setupgradingCost(ruestCost));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.