Debug后 Str为null list.size()为空指针?
URL httpUrl; try { httpUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection(); conn.setReadTimeout(5000); conn.setRequestMethod("GET"); BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuffer sb=new StringBuffer(); System.out.println(""+reader.readLine()); String str; //这边为空 while ((str=reader.readLine())!=null) { sb.append(str); } System.out.println(""+sb.toString()); final List<Person> data=parseJson(sb.toString()); handler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub adapter.setData(data); listView.setAdapter(adapter); } });
还有就是list.size()为空指针。
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference