1

我正在尝试使用 flickrj 向 Flickr 发送单个 ping 测试。我正在一步一步地按照教程here

https://github.com/callmeal/Flickr4Java

导入所有 Maven 依赖项和所有内容,最后得到以下代码:

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);

    }
}

我收到以下错误:

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)

我究竟做错了什么?

4

2 回答 2

0

根据此处的文档,您需要一个演员表

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

签名是..

public Collection<Element> echo(Map<String, String> params) throws  FlickrException {
....
    return response.getPayloadCollection();
}
于 2015-08-11T08:40:11.660 回答
0

您可能在导入中存在冲突,您正在使用 com.flickr4java.flickr.collections.Collection 而您很可能 - 作为echo方法返回类型状态 - 想要使用 java.util.Collection 类。将行替换为:

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

您的代码:

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);

    }
}
于 2015-08-11T08:51:25.253 回答