我想連接我的android設備到我的sql數據庫使用我的本地ip地址我的電腦,但沒有任何反應。我有錯誤。httpurlconnection本地ip地址
超時而檢索用於BufferedReader中[在BufferedReader.class所附的javadoc [java.io中的[在E:\安裝\應用\ Eclipse的\ SDK \ Android的SDK-WINDOWS \平臺\ Android的23 \一個droid.jar]]]
從我的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);
}
}
任何建議,將不勝感激。
將錯誤添加到您的帖子。在這篇文章中,你錯過了一個'}'。我希望它存在於你的代碼中。 –
超時檢索BufferedReader [在BufferedReader.class [在E:\ Installer \ Application \ Eclipse \ sdk \ android-sdk-windows \ platforms \ android-23 \ android.jar]中的java.io中附加的javadoc] ] – ariel
java.lang.RuntimeException:執行doInBackground()時發生錯誤 - 來自我的日誌cat – ariel