0

tring to use the bing api with java (not android)

hava this code :

import java.util.Iterator;

import net.billylieurance.azuresearch.AbstractAzureSearchQuery.AZURESEARCH_FORMAT;
import net.billylieurance.azuresearch.AzureSearchResultSet;
import net.billylieurance.azuresearch.AzureSearchWebQuery;
import net.billylieurance.azuresearch.AzureSearchWebResult;


public class mainTest {

    public static void main(String[] args){

        AzureSearchWebQuery aq = new AzureSearchWebQuery();

        String ACCOUNT_KEY = "WgQGPMPJH0FKBc/aWdiAeb05PiChO5XToKfDSmZ/Xuo";
        aq.setAppid(ACCOUNT_KEY);

        aq.setFormat(AZURESEARCH_FORMAT.XML);

        // searchParam is the field containing the keyword to be searched.
        aq.setQuery("games");

        aq.doQuery();

        AzureSearchResultSet<AzureSearchWebResult> azureSearchResultSet = aq
        .getQueryResult();

        for (Iterator<AzureSearchWebResult> iterator = azureSearchResultSet
        .iterator(); iterator.hasNext();) {
        AzureSearchWebResult result = (AzureSearchWebResult) iterator
        .next();

        // Populate the data from result object in to your custom objects.

        System.out.println(result.getTitle());
        System.out.println(result.getUrl());
        System.out.println(result.getDisplayUrl());
        System.out.println(result.getDescription());


        }




    }

also my jars :

apache-httpcomponents-httpcore
azure-bing-search-java-0.12.0
httpclient-4.2.3
org-apache-commons-logging

but got the error :

Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
  at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
  at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
  at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
  at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
  at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
  at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
  at net.billylieurance.azuresearch.AbstractAzureSearchQuery.doQuery(AbstractAzureSearchQuery.java:338)
  at mainTest.main(mainTest.java:38)

i read some where that maybe the jars are not compatible with each other. but dot know how to check that. or maybe something else .

any advice would be greate.

igor
  • 716
  • 1
  • 9
  • 27
  • Maybe you don't want to post your API-key in public. – Joachim Rohde Sep 10 '14 at 13:22
  • it only for testing maybe some one would like to check my code. – igor Sep 10 '14 at 13:24
  • 1
    Which version of httpcore are you using? It might be not compatible with the version of httpclient you are using (see http://stackoverflow.com/questions/18246979/java-lang-nosuchfielderror-def-content-charset) – Joachim Rohde Sep 10 '14 at 13:25
  • updated all and it seemsto be working but on line aq.doQuery(); it stack (infinent loop). any idias why ? – igor Sep 10 '14 at 13:42
  • I have no clue. But for a new problem you might want to ask a new question (since half of your current post has nothing to do with your current problem anymore). – Joachim Rohde Sep 10 '14 at 14:01

1 Answers1

0

You have two or more httpcore jars in your classpath.