0

Flickr Web サイトからクロールされた画像 ID のリストがあります。

その場所(緯度と経度)を取得する必要があります

これは私のコードです

File source = //images id 
File target = // images location

Scanner scanner = null;
PrintStream pStream =null;
String apiKey = //;
Flickr flick = new Flickr(apiKey);

PhotosInterface photosInterface=    flick.getPhotosInterface();
try {
    scanner= new Scanner(source);
    pStream= new PrintStream(target);       
    while (scanner.hasNext())
    {       
        String line = scanner.nextLine();       
        if (photosInterface.getPhoto(line).getGeoData()!=null)
        {
            pStream.println(Float.toString(photosInterface.getPhoto(line).getGeoData().getLatitude())+"\t"+Float.toString(photosInterface.getPhoto(line).getGeoData().getLongitude()));
        }
        else pStream.println("null");
    }           
    System.out.println(lineNumber);
}
catch (Exception e) {
}

}

この場合、この命令を実行したい

pStream.println("null");

の場合には:

画像が利用できない ( FlickrException)

または、画像が GeoData に関連付けられていません

これを行う方法?

4

1 に答える 1

0

ブロックをスローFlickrExceptionする呼び出しを囲む必要があると思います。try {..} catch

たとえば、利用可能な画像がない場合にphotosInterface.getPhoto(line)をスローできる場合は、次のようになります。FlickrException

while (scanner.hasNext())
{       
    String line = scanner.nextLine();       
    try {
        if (photosInterface.getPhoto(line).getGeoData()!=null)
        {
            pStream.println(Float.toString(photosInterface.getPhoto(line).getGeoData().getLatitude())+"\t"+Float.toString(photosInterface.getPhoto(line).getGeoData().getLongitude()));
        }
        else pStream.println("null");
    } catch (FlickrException fe) {
        // You may need to check something about the exception
        // here in case it can be thrown for a different reason
        // than images are not available 
        pStream.println("null");
    }
}           
System.out.println(lineNumber);
于 2013-04-23T21:30:16.447 に答える