的Android調用頁面我有我從我所返回的JSON文本,但Java代碼Android應用程序調用一個aspx頁面下方突破這裏BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
返回JSON錯誤
,此錯誤。
錯誤android.os.NetworkOnMainThreadException
你能幫助plesae?由於
default.aspx return json
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
//Write the message
Response.Write("{'testvar':'testtext'}");
//End the response causing it to be sent
Response.End();
}
}
的Android的Java
public void connectWCF() {
try {
URL json = new URL("http://localhost:50851/Default.aspx");
URLConnection jc = json.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
reader.close();
} catch(Exception e){
}
鏈接在那裏我得到的代碼的想法從 http://wyousuf.wordpress.com/2012/03/01/android-with-wcf-services/ http://matijabozicevic.com/blog/android-development/android-with-wcf-service
從的AsyncTask調用函數connectWCF(),東陽你不能在主線程服務器交互。 –
http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception –
爲什麼你的Android應用程序試圖連接到你的WCF服務**在手機上而不是在它的服務器上? –