2014-02-11 54 views
0

這是我的代碼。我在這行JSONObject json = new JSONObject(builder.toString());錯誤,我無法解決,有人可以告訴我是否犯了錯誤。這是我在這一行得到的錯誤'無法初始化類型jsonobject'。無法初始化類型jsonobject

public class Findrss { 

    public static <JSONObject> void main(String[] args) { 
     URL url = new URL("https://ajax.googleapis.com/ajax/services/feed/find?" 
     + "v=1.0&q=Official%20Google%20Blog&userip=INSERT-USER-IP"); 
     java.net.URLConnection connection = url.openConnection(); 
     String ref = "google.com"; 

     connection.addRequestProperty("Referer", ref); 

     String line; 
     StringBuilder builder = new StringBuilder(); 
     BufferedReader reader = new BufferedReader(
      new InputStreamReader(connection.getInputStream())); 

     while((line = reader.readLine()) != null) { 
      builder.append(line); 
     } 

     JSONObject json = new JSONObject(builder.toString()); 
    } 

} 

回答

0

您是使用IDE還是隻是記事本?您的代碼會拋出三個例外:MalformedURLException,IOExceptionJSONException。使用try-catch來修復它。

+0

我正在使用eclipse來做到這一點 – user3291784

+0

我在哪裏使用try catch,你能編輯我的代碼 – user3291784

+0

你是認真的嗎?這是java的基礎知識。 Eclipse可以爲你做到這一點。 – Sergi

相關問題