このクラスを使いたい
これは私のコードです (私の目的は、すべてのタグ間のペアごとの Google 距離を計算することです)
public static void main(String args[]) throws FileNotFoundException {
Scanner s = new java.util.Scanner(new File (yyy));
try {
GoogleDistanceCalculator googleDistanceCalculator =
new GoogleDistanceCalculator();
ArrayList<String> Alltags = new ArrayList<String>();
while (s.hasNext()) {
Alltags.add(s.next());
}
ArrayList<Double> arraysNGD = new ArrayList<Double>();
for (int i = 0; i < Alltags.size(); i++) {
for (int j = 0; j < Alltags.size(); j++) {
if (j!=i)
arraysNGD.add(
googleDistanceCalculator.calculateDistance(
Alltags.get(i).trim(), Alltags.get(j).trim()));
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
エラー
org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:508)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:55)
注意
たとえば試してみると
googleDistanceCalculator.calculateDistance("forest","plant");
エラーなく正常に動作します
編集
nature sky
org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:508)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:51)
nature blue
org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:508)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:51)
nature water
org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:508)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:51)
nature clouds