Search code examples
javaapitypestype-mismatchflickrj

How to send a simple ping test to Flickr with Flickrj api


I am trying to send a single ping test to Flickr using flickrj. I am following step by step the tutorial here

https://github.com/callmeal/Flickr4Java

imported all the maven dependencies and everything and ended up with the following code:

import java.util.Collections;

import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.REST;
import com.flickr4java.flickr.collections.Collection;

import com.flickr4java.flickr.test.TestInterface;

public class hello {
    public static void main(String args[]){


    String apiKey = "3f7046fe0897516df587cc3e6226f878";
    String sharedSecret = "9d0ceef5f2f3040f";
    Flickr f = new Flickr(apiKey, sharedSecret, new REST());
    TestInterface testInterface = f.getTestInterface();
    Collection results = testInterface.echo(Collections.EMPTY_MAP);

    }
}

I get the following error though:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from Collection<Element> to Collection

    at hello.main(hello.java:18)

What am I doing wrong?


Solution

  • You might have a conflict in imports, you are using com.flickr4java.flickr.collections.Collection while you most probably - as the echo method return type states - want to use java.util.Collection Class. replace the line with:

    java.util.Collection<Element> results = testInterface.echo(Collections.EMPTY_MAP);
    

    Your Code:

    import java.util.Collections;
    
    import com.flickr4java.flickr.Flickr;
    import com.flickr4java.flickr.REST;
    import com.flickr4java.flickr.collections.Collection;
    
    import com.flickr4java.flickr.test.TestInterface;
    
    public class hello {
        public static void main(String args[]){
    
    
        String apiKey = "3f7046fe0897516df587cc3e6226f878";
        String sharedSecret = "9d0ceef5f2f3040f";
        Flickr f = new Flickr(apiKey, sharedSecret, new REST());
        TestInterface testInterface = f.getTestInterface();
        java.util.Collection<Element> results = testInterface.echo(Collections.EMPTY_MAP);
    
        }
    }