1

I'm getting a "Cannot be resolved or is not a field" error on a variable in one of my Java classes, and I don't understand why... I've had a look online, but can't find anything that really explains why I'm getting it. The error is happening in the following for loop:

int i;
getFilterConditions();
for(i = 0; i < sitesToBeFiltered.size(); i++){
    if(sitesToBeFiltered.get(i) == filter1Value){
        Gui.displayFilteredOutput.append("\n");
    Gui.displayFilteredOutput.append("EID: [" + sitesToBeFiltered.get(i) + ", " + applicationsToBeFiltered.get(i) + ", " + IDsToBeFiltered.get(i) + "]. ");
    Vector3Double filteredEntityPosition = 
    Gui.displayFilteredOutput.append("Location in DIS coordinates: [" + sitesToBeFiltered.get(i).positionsToBeFilteredX.get(i));
    }
}

It's being generated on the positionsToBeFilteredX.get(i) variable at the end of the for loop. I have defined that variable as a global variable at the top of the class using the line:

public static ArrayList<Double> positionsToBeFilteredX = new ArrayList<Double>();

To explain what I'm trying to do here:

I have a program that is reading the PDUs that are being sent/ received over a network, and storing both the PDUs themselves, and information held by each of the PDUs in a number of ArrayLists. What I'm trying to do with this code, is to take a value entered by the user on a form (stored in the filter1Value integer variable), and check whether that value is equal to any of the elements in a particular ArrayList (sitesToBeFiltered).

So, I am looping through the sitesToBeFiltered ArrayList, and checking every element to see whether it is exactly equal to the value of filter1Value. If it is, I am then appending some text about the matching ArrayList element to a JTextArea (displayFilteredOutput).

One of the things I want to add to the JTextArea is the X position of the matching element (which was added to the positionsToBeFilteredX when it was found that that the element matched the user's search criteria.

So what I'm trying to do with the last line of code is to append the X coordinate (stored in an array of X coordinates) of the matching element in the sitesToBeFiltered ArrayList, to the displayFilteredOutput JTextArea, but for some reason, I'm getting this "cannot be resolved, or is not a field" compile error on the variable.

Can anyone explain to me why this is? I suspect that I am not referencing the X coordinate of the element matching the filter value correctly, but I'm not sure how I should be doing this... Could someone point me in the right direction?

4
  • Does the error state which symbol it is referring to? It seems that the method positionsToBeFilteredX() doesn't exist in whatever class is in sitesToBeFiltered based on what you are saying. Commented May 7, 2014 at 10:58
  • No, it doesn't say anything about any symbols just gives the message "positionsToBeFilteredX cannot be resolved or is not a field"... positionsToBeFilteredX is not a method though- it is a variable of type ArrayList<Double>, i.e. an ArrayList of Doubles- as mentioned in my original post. Commented May 7, 2014 at 11:02
  • I am calling a get method on that variable, to get the element at position 'i' in the ArrayList. Commented May 7, 2014 at 11:04
  • Look at the answer provided below: positionsToBeFilteredX DOES NOT EXIST in the class of the objects contained in sitesToBeFiltered. It maybe a typo or a confusion on your part. Nothing more can be said with the information you provided. Commented May 7, 2014 at 11:07

2 Answers 2

2

Your code is written as though positionsToBeFiltered is a field in the object returned by sitesToBeFiltered.get(i). Evidently it isn't.

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

3 Comments

I suspected that this might be the case- but as mentioned, I'm not sure how I should be doing it... I tried changing that line to just Gui.displayFilteredOutput.append("Location in DIS coordinates: [" positionsToBeFilteredX.get(i));, but when I do this, I get a compile error that says "Type mismatch: cannot convert from void to Vector3Double"...
You're giving us incomplete information. You haven't said what the declaration of sitesToBeFiltered is, for instance. Try making every statement simple instead of stringing them together; y = x.get(i); and y.append(z);, etc.; then it is easier to figure out what the error message refers to. Java error messages are excellent once you know something about what they're talking about (other languages aren't always as nice this way).
sitesToBeFiltered has been declared at the top of the class with the line public static ArrayList<Integer> sitesToBeFiltered = new ArrayList<Integer>();
1

Should have seen it sooner: the issue was because I was trying to assign the value to a variable that was of an incompatible type. To solve this, I just needed to append the value to the JTextArea in the Gui without assigning it to a variable first: i.e. instead of writing

Vector3Double filteredEntityPosition = Gui.displayFilteredOutput.append("Location in DIS coordinates: [" + positionsToBeFiltered.get(i);

I just needed to write:

Gui.displayFilteredOutput.append("Location in DIS coordinates: [" + positionToBeFiltered.get(i) + "]. ");

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.