i created one method to read the data from mysql. when and trying to open my application is getting stop pls help me.

  • Replies:1
syed
  • Forum posts: 3

Aug 10, 2016, 12:56:50 PM via Website

private String getData(){
// Connect and get a streams
InputStream inputStream = null;
String data = null;
try {
URL url = new URL(address);
HttpsURLConnection con = (HttpsURLConnection) 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;

}
My error was

java.lang.ClassCastException: com.android.okhttp.internal.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection
at info.androidhive.slidingmenu.adapter.ContentAdapter.getData(ContentAdapter.java:63)
at info.androidhive.slidingmenu.adapter.ContentAdapter.doInBackground(ContentAdapter.java:40)
at info.androidhive.slidingmenu.adapter.ContentAdapter.doInBackground(ContentAdapter.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

— modified on Aug 10, 2016, 1:05:53 PM

Reply
syed
  • Forum posts: 3

Aug 10, 2016, 1:34:22 PM via Website

How Can i pass this.class context in my main activity

public class Home extends Fragment {
String url = "";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.home, container, false);
        final  ListView lv = (ListView) rootView.findViewById(R.id.lv);

        final ContentAdapter adapter = new ContentAdapter(this, url, lv);
           adapter.execute();
       return  rootView;

    }

}

Reply