使用Google 3D饼图工具时是否存在Nullpointer异常?

时间:2014-07-10 08:34:39

标签: android image http bitmap

我在这里使用完全相同的代码 Link

在我的项目中显示3D饼图..代码没问题。我正确地获取URL的LOG,当我在浏览器中使用链接时它正确地显示图表..但是当我试图通过将其转换为位图来将图像显示到我的应用程序内的图像视图时,它给出了空指针例外,,,

private Bitmap loadChart(String urlRqs){
  Bitmap bm = null;
  InputStream inputStream = null;

  try {
   **inputStream = OpenHttpConnection(urlRqs);
   bm = BitmapFactory.decodeStream(inputStream);
   inputStream.close();**
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return bm;
 }

 private InputStream OpenHttpConnection(String strURL) throws IOException{
  InputStream is = null;
  URL url = new URL(strURL);
  URLConnection urlConnection = url.openConnection();

  try{
   HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
   httpConn.setRequestMethod("GET";
   httpConn.connect();

   if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
    is = httpConn.getInputStream(); 
   }
  }catch (Exception ex){
  }

  return is; 
 }

0 个答案:

没有答案