最近,我開始從我的小部件得到以下錯誤。我沒有做任何改變,我想知道這個問題會是什麼,以及如何解決這個問題。我的窗口小部件根據我創建的用於訪問第三方客戶端信息的服務信息進行更新。我幾天前纔得到數據。現在我收到下面的錯誤。未知的主機異常
我剛剛嘗試在活動(即非小工具)中運行代碼,它工作正常。我不確定它爲什麼在一個活動中起作用,但不是一個小部件。我還在單獨的Intent中訪問第三方網站。
我已經嘗試重新啓動模擬器,eclipse和重新啓動設備。我的清單文件具有訪問Internet的適當權限。這個問題最初似乎是一個網絡問題,但我確認我可以從模擬器和設備上的網絡瀏覽器訪問URL。代碼剛好在幾天前工作。我已經用我的清單文件更新了這篇文章。代碼在調用parseMyInfo之前就會失敗。在OAuth使用者/提供者調用期間拋出異常。
錯誤
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
08-24 22:36:02.063: ERROR/ARCHOS(541): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
08-24 22:36:02.063: ERROR/ARCHOS(541): at com.test.community.SG_Service$TED.populate(SG_Service.java:276)
08-24 22:36:02.063: ERROR/ARCHOS(541): at com.test.community.SG_Service$SGHandler.getTEDData(SG_Service.java:813)
08-24 22:36:02.063: ERROR/ARCHOS(541): at com.test.community.SG_Service$SGService_BG.onHandleIntent(SG_Service.java:844)
08-24 22:36:02.063: ERROR/ARCHOS(541): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
08-24 22:36:02.063: ERROR/ARCHOS(541): at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 22:36:02.063: ERROR/ARCHOS(541): at android.os.Looper.loop(Looper.java:123)
08-24 22:36:02.063: ERROR/ARCHOS(541): at android.os.HandlerThread.run(HandlerThread.java:60)
08-24 22:36:02.063: ERROR/ARCHOS(541): Caused by: java.net.UnknownHostException: communitymonitorstudy.stepgreen.org
08-24 22:36:02.063: ERROR/ARCHOS(541): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
08-24 22:36:02.063: ERROR/ARCHOS(541): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
08-24 22:36:02.063: ERROR/ARCHOS(541): at java.net.InetAddress.getAllByName(InetAddress.java:242)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-24 22:36:02.063: ERROR/ARCHOS(541): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-24 22:36:02.063: ERROR/ARCHOS(541): at oauth.signpost.commonshttp.CommonsHttpOAuthProvider.sendRequest(CommonsHttpOAuthProvider.java:64)
08-24 22:36:02.063: ERROR/ARCHOS(541): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:177)
失敗代碼 多數民衆贊成失敗的代碼如下:
HttpClient client = new DefaultHttpClient();
consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider(Constants.REQUEST_TOKEN_URL,
Constants.ACCESS_TOKEN_URL, Constants.AUTHORIZE_URL, client);
provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
provider.retrieveAccessToken(consumer, null);
MyInfo info = parseMyInfo(userName, consumer, client);
清單文件
<application android:icon="@drawable/icon" android:debuggable="true"
android:label="@string/app_name" android:name="AppStatus">
<activity android:name=".CommunityMonitorActivity"android:label="@string/app_name">
<intent-filter>
<action android:name="com.cmu.community.CommunityWidget.ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<activity android:name=".MyInfoActivity"
android:theme="@style/Theme.D1"
android:label="@string/my_info"
/>
<activity android:name=".HomeActivity"
android:theme="@style/Theme.D1"
android:label="@string/home"
/>
<activity android:name=".AboutActivity"
android:theme="@style/Theme.D1"
android:label="@string/about"
/>
<receiver android:name=".CommunityWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.cmu.community.CommunityWidget.ACTION_WIDGET_RECEIVER"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/communitywidgetprovider" />
</receiver>
<receiver android:name="com.cmu.community.Stepgreen_Service$StepgreenReceiver">
<intent-filter>
<action android:name="com.cmu.community.ACTION_STEPGREENMANAGER"></action>
</intent-filter>
</receiver>
<receiver android:name="com.cmu.community.AppStatus_Service$AppStatusReceiver">
<intent-filter>
<action android:name="com.cmu.community.ACTION_APPSTATUSMANAGER"></action>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-
permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<service android:name="Stepgreen_Service$StepgreenService_BG"></service>
</application>
</manifest>
'UnknowHostException'通常意味着您的DNS系統無法解析主機名。 – asgs
不知道爲什麼這是downvoted。我贊成你支持。可能是由於精英紳士編輯之前的看法。 :)和asgs是正確的,我會仔細檢查,你有互聯網許可啓用,這將是我的第一步。 – Codeman
您是否確定您的許可在manifest.xml中是正確的?你可以將它添加到你原來的文章嗎? – elevine