Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

The method is undefined for the type error

 
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use the Iterables type from Google core library but I keep getting an error:

I'm following the Doing cool data science in Java: how 3 DataFrame libraries stack up article and github example like so:

I also tried copying the exact example from the github example with their csv but I still got the error.

Thanks so much!
 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it's String
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "now". Did you just add it? Did it fix the error message?
If yes, I would think you'd get a null pointer exception at run time because you haven't initialized it to anything.
 
Master Rancher
Posts: 3701
44
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure these questions are helping.  In the original code shown by Glenda, "name" was a lambda parameter, not declared to be anything - its type was supposed to be inferred.  Something was apparently leading to a failure to infer the correct parameters; I'm not sure why.  Adding "String name" in front on another line just creates a new local variable "name", not the same as the lambda parameter.

Glenda, try dropping that new "String name;", and changing

to

Does that fix things, or at even change the error message in any way?  (None of those changes should be needed - but they allow us to be sure what types are being used here.)

Is there an import statement for Iterables?  Is it

or is it something else?

Also, are you using an IDE of some sort?  IntelliJ, Eclipse, or some other?  Can you run javac from the command line, and does it give the same error?  I'm asking because I don't recall seeing the error messge you describe, so I'm wondering what source it comes from.
 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
So I removed
And I changed the code and the error changed to:
There is an import statement, and yes that's it:

Yes I'm using eclipse, I tried running from the terminal and I got a bunch of errors, seems the imported jar files didn't come along with javac.
 
Marshal
Posts: 25963
70
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Glenda Karen wrote:Yes I'm using eclipse, I tried running from the terminal and I got a bunch of errors, seems the imported jar files didn't come along with javac.



No, the jar files which contain the classes from package joinery and the Google core library aren't part of the Java compiler. You would have to include them in the classpath when using the javac command. So they aren't helpful if you didn't do that. (And right now I don't think it's a good use of time to try to explain how to provide javac with a classpath.)

But you must have included them in your Eclipse project's build path (right?), otherwise you would be getting the same errors in Eclipse, in the form of red flags next to those lines and red underlines to indicate the specific problem. So is it correct to say that the error message you reported in your original post came from Eclipse, associated with a red underline? And are there other such error messages?
 
Bartender
Posts: 4109
156
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you didn't get these errors when using eclipse, (not in the other topic as well) so I'd say stick to eclipse.

And that gives thar error also, so I suspect an inference problem, like Mike mentions.

According to the documentation, dataFrame.columns() returns a Set<Object> with all the names of the columns (but what about the order of the names?), and Iterables.indexOf requires an Iterable<T> and a Predicate<T>.

To test whether it is an inference problem, lets make the arguments explicit:



and see if the same error appears.

However, to get all the values of the column("height"), there is a much easier way. Look at the dataframe.col(Object) method, that returns a List<Object> with all the values in that column.
 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much!

Piet Souris wrote:

To test whether it is an inference problem, lets make the arguments explicit:

and see if the same error appears.


So I tried this out and I got the following errors:

Look at the dataframe.col(Object) method

Thanks!
 
Mike Simmons
Master Rancher
Posts: 3701
44
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Glenda Karen wrote:


Wait a minute... DataFrame.Predicate?  Turns out there's a nested Predicate interface inside DataFrame.  But that's not the one we want here.  Try changing to

And actually...


That makes no sense to me... try changing it further:
 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much!

So now I'm getting this error:
 
Piet Souris
Bartender
Posts: 4109
156
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gets weirder and weirder. Just a desparate last test. Can you replace

by

Another thing that is strange is the error:

Would that mean that this Object in "Set<Object>"  is in reality a List<Object>? It does not say so in the API. Can you check the size of this Set<Object>?

Do you know of a tutorial for this DataFrame class?
 
Mike Simmons
Master Rancher
Posts: 3701
44
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:
Another thing that is strange is the error:

Would that mean that this Object in "Set<Object>"  is in reality a List<Object>? It does not say so in the API. Can you check the size of this Set<Object>?



To me it suggests that the DataFrame was defined as a DataFrame<List<Object>>.  Which is not what we were shown, but perhaps the code was changed at some point?  

I feel like at least one of these classes is not what we think it is.  (Like Predicate was DataFrame.Predicate.). Let's make all the packages explicit:

 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:I feel like at least one of these classes is not what we think it is.  (Like Predicate was DataFrame.Predicate.). Let's make all the packages explicit:


So I tried this and I'm getting this error now:

Piet Souris wrote:Can you replace

by


I tried this as well but still got an error for indexOf

I don't think I have found any tutorials using joinery but I have been trying out some other DataFrame libraries, so far nRo/DataFrame has worked for some other things but I got stuck trying to find a way to get indexes so I'm not sure if it will work with indexOf either.
 
Paul Clapham
Marshal
Posts: 25963
70
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at the API documentation for Iterable, as linked to in the original post. And ouch! Predicate is indeed not what you thought it was!
 
Marshal
Posts: 70689
288
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you get the no such method compiler error corrected? If you go through its documentation, you will find that the second argument has to be a Predicate (the Guava version, not java.util.function.Predicate), and the λ you provided isn't a Predicate. It is something with a public void apply(T t) ... method, and Predicate should have public boolean apply(T t) ....
 
Piet Souris
Bartender
Posts: 4109
156
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's it, Campbell. I just clicked on the Predicate<T> in the indexOf method of the Iterables class, and that leads to 'com.google.common.base'. So we are dealing with three Predicates here!
Reason enough to ditch that Iterables class.

Now, I didn't see an easy way in the DataFrame to get the index of a column, but assuming that dataframe.columns() delivers a Set<Object> with Object being a List<Object> where each object is a String, and that Set has only one element:

A lot of assumptions! I tried this code in java:
 
Piet Souris
Bartender
Posts: 4109
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed Pauls reply. So also to Paul: well done!
 
Campbell Ritchie
Marshal
Posts: 70689
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . three Predicates here!

I only saw two, but you are right that Paul C noticed it first.

Reason enough to ditch that Iterables class. . . .

Not necessarily, maybe not if you look on it as an extension of Collections.
 
Glenda Karen
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much everybody for all your help, much appreciated! Very interesting hearing about all this stuff and learning new things too.
 
Piet Souris
Bartender
Posts: 4109
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was for us a pleasure to help, and I learned a thing or two too!
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic