First, I need to say that I tried found explanation in internet, but all are unclear for me.
I worte a program in java FX. One of classes has method generating two list:
listA = [0,2,3,4,1,2,5,12,3,2,1,3] listB = [2,3,4,1,2,1,2,3,1,2,3,4] I need to return that lists so I connect it in one:
ArrayList<List<Integer>> result = new ArrayList<List<Integer>>(); result.add(listA); result.add(listB); return(result); head of that method looks that:
static public List man() { #could be usefull to explain me how to fix my code. So now in another class i call the method:
List newList= classTest.man(); And print it:
System.out.println(newList); So I got:
[[0,2,3,4,1,2,5,12,3,2,1,3][2,3,4,1,2,1,2,3,1,2,3,4]] And it's fine, I just want a write a loop to fill data for my chart:
for(int i; i < newList.get(0).length(); i++){ String iterationNum= Integer.toString(newList.get(0).get(i); series.getData().add(new XYChart.Data<String, Number>(iterationNum; newList.get(0).get(i))); But first:
1. .length() is red : error = "Cannot resolve symbol 'length'" 2. in newList.get(0).get(i) the second .get(i) is red. error = "Cannot resolve method 'get' in 'Object'" Please, can someone help me solve my problem? I wrote almost whole of program, and stuck here.
42 Answers
length is red : error = "Cannot resolve symbol 'length'"
.length is used to get the length of an array. You are using, I assume, java.util.List. You need to use the method size, e.g. newList.get(0).size()
in newList.get(0).get(i) the second .get(i) is red. error = "Cannot resolve method 'get' in 'Object'"
static public List man() I'm not sure what this method does, but you are using a raw type. This means that the List you are getting back is basically equivalent to List<Object>.
So you are trying to call Object#get(i), and get is not a valid method on an Object. You need to specify what type List man() will return. For instance, List<Integer> man(), or whatever type it needs to be. I can't tell from your code what you're actually doing.
".length" is used to determine the Length of an array. For lists you use ".size()"
Try replacing it with
((List<Integer>) newList.get(0)).get(i);