Java を使用して JSON 応答をデコードするアプリケーションを開発しています。以下は、時折 NullPointerException が発生するコード スニペットです。
JSONParser parser=new JSONParser();
URL url=new URL("http://api.yummly.com/v1/api/recipes?q="+
URLEncoder.encode(dish,"UTF- 8")+"&_app_id=APP_ID8&_app_key=APP_KEY");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
Object json=parser.parse(br);
JSONObject obj=(JSONObject)json;
if(obj!=null)
count=(long)obj.get("totalMatchCount"); <--- Exception at this point
このステートメントはループで実行されており、ランダムな反復で NullPointerException が発生しています。