2012-02-07 19 views
2

我的android客戶端與部署在jboss上的servlet建立URL連接。但是,當我在仿真器中運行客戶端似乎沒有建立連接。我的客戶代碼:Android客戶端與jboss服務器通信

URL url = new URL("http://192.168.56.1:8080/hello"); 
       URLConnection connection = url.openConnection(); 
       connection.setDoOutput(true); 
       ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream()); 
       String s=new String("success"); 
       out.writeObject(s); 
       out.flush(); 
       out.close(); 

在jboss中沒有響應。 192.168.56.1是我的機器的IP地址。由於'localhost'將引用模擬器本身,因此我使用了192.168.56.1。(ipcofig) 這是什麼問題。

這是我做了建議的修改後(即在android manifest.xml中給了internet權限,並將URL改爲'http://10.0.2.2:8080/hello'來引用我的機器)。

ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.Client/.ClientActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET 

現在工作: 但我還是當我運行我的應用程序(客戶端)得到這個例外。我將互聯網權限添加到清單標籤。之前我已將它添加到應用程序標籤中。 參考我的原始問題,在做出所有建議的更改後,仍然沒有來自jboss服務器evene的響應。仿真器和jboss服務器之間似乎沒有連接。

+0

您是否在清單文件中添加了Internet權限? – kosa 2012-02-07 16:31:07

+0

<使用權限 android:name =「android.permission.INTERNET」/> – kosa 2012-02-07 16:41:30

+0

請參閱此鏈接http://developer.android.com/resources/samples/SampleSyncAdapter/AndroidManifest.html – kosa 2012-02-07 16:42:13

回答

1

因此,假設您的JBoss服務器是在同一臺PC上運行作爲你的模擬器,這裏 有幾件事情你可以檢查:

首先,請確保您有Internet許可,您 AndroidManifest.xml爲 設置Thinksteep 指出:

<uses-permission android:name="android.permission.INTERNET" /> 

其次,嘗試更改IP地址:

URL url = new URL("http://192.168.56.1:8080/hello"); 

要:

URL url = new URL("http://10.0.2.2:8080/hello"); 

詳細here。基本上這是假設你的JBoss在你的開發機器上服務於localhost(即服務於127.0.0.1),你的模擬器應該能夠通過這個特殊的IP地址進行連接。

+0

我只添加了Internet權限我的android.xml文件。我已經設置了包含Internet權限的權限。但是,在運行以下異常時會發生.ActivityManager:java.lang.SecurityException:Permission Denial:starting Intent {act = android.intent.action.MAIN cat = [android.intent.category。 LAUNCHER] flg = 0x10000000 cmp = com.epramaan/.EpramaanActivity} from null(pid = -1,uid = -1)需要android.permission.INTERNET – Ashwin 2012-02-08 01:37:31

+0

我已經根據您的請求編輯了該問題。 – Ashwin 2012-02-08 02:03:00

+0

請參閱我的第二次編輯。現在沒有例外。但仍然沒有從jboss服務器的響應。 – Ashwin 2012-02-08 02:16:36