0

YouTube へのリクエストを作成しようとしており、取得した json-c の結果を解析しようとしています。コードが機能しておらず、例外がスローされています。どこが間違っているのですか?親切に助けて

MainActivity.java

    try{
        HttpClient client = new DefaultHttpClient();

        HttpUriRequest request = new HttpGet("https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&category=autos&max-results=1&orderby=relevance&q="+searchTerm);

        HttpResponse response = client.execute(request);

        String jsonString = StreamUtils.convertToString(response.getEntity().getContent());

        JSONObject json = new JSONObject(jsonString);

        JSONArray jsonArray = json.getJSONObject("data").getJSONArray("items");

        JSONObject jsonObject = jsonArray.getJSONObject(0);

        String title = jsonObject.getString("title");
        Toast.makeText(getApplicationContext(), title, Toast.LENGTH_LONG).show();
        }
        catch(Exception e)
        {
            Log.d("YOUTUBE", e.getMessage());


        }

StreamUtils.java

     public class StreamUtils {
  public static String convertToString(InputStream inputStream) throws IOException     {
    if (inputStream != null) {
        Writer writer = new StringWriter();

        char[] buffer = new char[1024];
        try {
            Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 1024);
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            inputStream.close();
        }
        return writer.toString();
    } else {
        return "";
    }
}

}

LOGCAT からの出力

01-06 21:15:00.328: E/AndroidRuntime(810): java.lang.RuntimeException: Unable to start    activity ComponentInfo{com.example.allinonedata/com.example.allinonedata.MainActivity}:   java.lang.NullPointerException: println needs a message
 01-06 21:15:00.328: E/AndroidRuntime(810):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
4

0 に答える 0