i created method to read the data from data base through php i getting an error while sellecting url package please help me...

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 3

Aug 16, 2016 7:39:31 AM via Website

protected String doInBackground(Void... params) {
    String data = getData();
    // TODO Auto-generated method stub
    return data;
}

public String getData(){
// Connect and get a streams
InputStream inputStream = null;
String data = null;
try {
URL url = new URL(address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
inputStream = new BufferedInputStream(con.getInputStream());

    BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream));

    StringBuffer stringBuffer = new StringBuffer();

    if(bufReader!= null){

        while ((data=bufReader.readLine()) != null) {

            stringBuffer.append(data+"\n");

        }
    }else {
        return null;
    }

    return stringBuffer.toString();

}catch(MalformedURLException e){
    e.printStackTrace();
    Log.e(" error while reaading1",Log.getStackTraceString(e));
}catch (IOException e) {

    // TODO: handle exception
    e.printStackTrace();
    Log.e(" error while reaading2",Log.getStackTraceString(e));
} catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    Log.e(" error while reaading3",Log.getStackTraceString(e));
} finally{
    if (inputStream != null) {
        try {
            inputStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.e(" error while reaading4",Log.getStackTraceString(e));
        }
    }
}
return null;

}

— modified on Aug 17, 2016 7:37:23 AM