我试图使用我的计算机的本地ip地址将我的android设备连接到我的sql数据库,但是什么也没有发生。我有错误。
在检索BufferedReader的附加javadoc时超时[在BufferedReader.class中[在java.io中) 从我的LogCat java.lang.RuntimeException:执行doInBackground()时发生的错误 导致: java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl无法转换为javax.net.ssl.HttpsURLConnection
class BackgroundTask extends AsyncTask< Void, Void, String>{
String json_url = "http://192.168.1.106/sample/sample.php";
HttpURLConnection httpsURLConnection = null;
@Override
protected String doInBackground(Void... params) {
try {
URL url = new URL(json_url);
httpsURLConnection = (HttpsURLConnection) url.openConnection();
InputStream inputStream = httpsURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
while((JSON_STRING = bufferedReader.readLine()) != null){
stringBuilder.append(JSON_STRING+"\n");
}
bufferedReader.close();
inputStream.close();
httpsURLConnection.disconnect();
return stringBuilder.toString().trim();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
@Override
protected void onPostExecute(String result) {
TextView textView = (TextView) findViewById(R.id.tvDisplay);
textView.setText(result);
}
}如有任何建议,将不胜感激。
发布于 2016-02-13 09:12:01
在这条线上-
httpsURLConnection = (HttpsURLConnection) url.openConnection(); 你应该做好-
httpsURLConnection = (HttpURLConnection) url.openConnection(); 在Http之后还有额外的服务。你把它投错了门。
发布于 2016-02-13 09:14:08
如果您使用“http”与您的本地服务器对话,请使用HttpURLConnection代替HttpsURLConnection。虽然'HttpsURLConnection‘是从'HttpURLConnection’继承而来的,但是当您错误地转换它时,它不会给您带来错误,但是当您在http上进行连接时,它可能会给您带来错误。
https://stackoverflow.com/questions/35377853
复制相似问题