欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android 4.0 HttpURLConnection. getInputStream() 为空的问题

程序员文章站 2022-03-05 11:51:11
...
public String downTxt(String urlStr) {
		StringBuffer sBuffer = new StringBuffer();
		String line = null;
		BufferedReader bReader = null;
		try {
			URL url = new URL(urlStr);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			bReader = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			while ((line = bReader.readLine()) != null) {
				sBuffer.append(line);
			}

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				bReader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		return sBuffer.toString();
	}

 走到

bReader = new BufferedReader(new InputStreamReader(
					conn.getInputStream())); 

 就会报空指针错误。为什么呢 ?

 ----------------

 <uses-sdk android:minSdkVersion="14"/> 改为 14以下版本。。。就OK。。。