0

It is an arraylist of arraylists of integers. I'm still running into an issue though when I try to compile. The command prompt says "incompatible types." I know for sure that all the function calls are correct (i.e.: .getStart(), .getEnd(), etc. - I wrote those classes and have tested them thoroughly.) Btw, "permOfEdges" is: ArrayList <ArrayList<Edge>> (Edge being a class I wrote.)

Since it's: visited.get(-).get(-), it says the second .get(-) should be a variable not a value. I'm confused on what it means since it's an arraylist of arraylists.

Code for arraylist of arraylists:

ArrayList<ArrayList<Integer>> visited = new ArrayList<ArrayList<Integer>>();
for(int i = 1; i < permOfEdges.size(); i++)
    {
        for(int j = 0; j < permOfEdges.get(i).size(); j++)
        {
            visited.get(i).get(j) = 0;  // this is to initialize the entire thing to only contain zeros
        }
    }
    for(int i = 1; i < permOfEdges.size(); i++)
    {
        for(Edge point: permOfEdges.get(i))
        {   
            if((visited.get(point.getEnd()).get(point.getStart()) == 0) && visited.get(point.getStart().get(point.getEnd()) == 0))  // means NOT visited yet
            {
                writer.println(point.getStart() + " " + point.getEnd() + " " + point.getDistance() + " " + point.getPrice());
            }
            visited.get(point.getStart()).get(point.getEnd()) = 1;
            visited.get(point.getEnd()).get(point.getStart()) = 1;
        }
    }

    writer.close(); 

The error reads: 1. unexpected types: visited.get(i).get*(j) = 0 (* = where the ^ was in the command prompt) required: variable found: value

  1. int cannot be dereferenced if((visited.get(point.getEnd()).get*(point.getStart()) == 0) &&...)
  2. and 4. both of these errors are the same as the first one except it focuses on the two lines where I assign visited.get(..).get(..) = 1

Any help would be much appreciated! Thank you!

9
  • **permOfEdges is ArrayList<ArrayList<Edge>> (Edge being a class I wrote) Commented Mar 26, 2015 at 23:07
  • don't comment your own question, rather update it. Commented Mar 26, 2015 at 23:10
  • I don't see where you create the inner List? Commented Mar 26, 2015 at 23:11
  • Which inner list? And sorry, I'm very new to stack overflow Commented Mar 26, 2015 at 23:16
  • The only error I have right now is that it doesn't like the if statement. It says that it is "int cannot be dereferenced" do you know what that means? @jangroth Commented Mar 26, 2015 at 23:17

1 Answer 1

1

You cannot assign to the result of a method call. This is wrong:

visited.get(i).get(j) = 1;

and you presumably meant:

visited.get(i).set(j, 1);
Sign up to request clarification or add additional context in comments.

8 Comments

Also, do you have any idea about why the if statement would be throwing an error?
@Nupur whoops, it's called set. (put is for maps)
Thank you! I realized, it shouldn't be .put(), it should be .set(). So I just have one error now and it is due to the if statement.
Do you have any ideas about why it would say that I am "dereferencing" the int??
@Nupur Because you are trying to call a method on an int, in another place. Also, one question per question...
|

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.