2014-02-11 49 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

相关问题