2012-02-16 27 views
1

我正在開發一個GWT應用程序以從Freebase獲取查詢結果。這是我的EntryPoint類的代碼。在Java中使用Freebase API

package com.google.tracker.client; 

import com.freebase.api.Freebase; 
import com.freebase.json.JSON; 
import com.google.gwt.core.client.EntryPoint; 

public class Tracker implements EntryPoint{ 

    public void onModuleLoad() { 
     Freebase freebase = Freebase.getFreebase(); 
     String query_str = "{" + 
       "'id': null," + 
       "'type': '/film/film'," + 
       "'name': 'Blade Runner'," + 
       "'directed_by': [{" + 
       "'id': null," + 
       "'name': null" + 
       "}]" + 
       "}​".replace('\'', '"'); 

     JSON query = new JSON(query_str); 
     JSON result = freebase.mqlread(query); 
     @SuppressWarnings("unused") 
     String director = result.get("result").get("directed_by").get(0).get("name").string(); 
    } 
} 

我收到以下錯誤:

[ERROR] Line 10: No source code is available for type com.freebase.api.Freebase; did you forget to inherit a required module? 
[ERROR] Line 21: No source code is available for type com.freebase.json.JSON; did you forget to inherit a required module? 

可能是什麼,這些可能的原因是什麼?

+0

除非您正在爲Google編寫此代碼,否則您不應該在代碼中使用com.google命名空間。 – 2012-02-18 16:20:31

回答

3

Freebase的API包不是GWT模塊,因此無法轉換爲Javascript。這就是爲什麼有「沒有可用的源代碼」。您需要從服務器撥打Freebase並將結果發送給客戶端。

+0

這可能是一個問題,我會盡力回覆在一天.. :) – 2012-02-16 17:45:34

+0

謝謝噸! – 2012-02-16 17:59:37

+0

檢查代碼編輯 – 2012-02-17 05:26:03