1

由于强制关闭,用户向我发送了此堆栈跟踪:

java.lang.IllegalStateException: Scheme 'https' not registered.
at org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)
at org.apache.http.impl.conn.DefaultHttpRoutePlanner.determineRoute(DefaultHttpRoutePlanner.java:107)
at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:581)
at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:923)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:473)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.augustinianum.augustinianum.AlarmService.doWakefulWork(AlarmService.java:70)
at com.commonsware.cwac.wakeful.WakefulIntentService.onHandleIntent(WakefulIntentService.java:106)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)

这是强制关闭类的最重要的代码,它是 Commonsware 的 WakefulIntentService ,它基本上只是一个普通的 IntentService 但是这个自动持有唤醒锁(不要认为这与异常有任何关系,但是以防万一)。此代码下载网页的 HTML 代码:

private DefaultHttpClient createHttpClient() {
        HttpParams my_httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        ThreadSafeClientConnManager multiThreadedConnectionManager = new ThreadSafeClientConnManager(my_httpParams, registry);
        DefaultHttpClient httpclient = new DefaultHttpClient(multiThreadedConnectionManager, my_httpParams);
        return httpclient;
    }


@Override
    protected void doWakefulWork(Intent arg0) {

        int mStatusCode = 0;
        String content = "";

        String url = "http://www.example.com/";

        DefaultHttpClient httpclient = createHttpClient();
        HttpGet httpget = new HttpGet(url);

        try {
            HttpResponse response = httpclient.execute(httpget);
            StatusLine statusLine = response.getStatusLine();
            mStatusCode = statusLine.getStatusCode();

            if (mStatusCode == 200){
                content = EntityUtils.toString(response.getEntity());
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

第 70 行(崩溃的地方)是这一行:

HttpResponse response = httpclient.execute(httpget);

在我的清单中,我只是这样声明:

<service
    android:name=".AlarmService">
</service>

奇怪的是,此异常并非发生在所有设备上,也并非总是在执行此代码时发生。大多数时候,这段代码执行得很好,但有时会发生这种异常。

有人知道我能做些什么吗?

非常感谢提前!

4

2 回答 2

2

您不需要 a ThreadSafeClientConnManager,因为 aIntentService只使用一个线程。我会删除所有这些东西,这将摆脱您的 custom SchemeRegistry,这可能会帮助您处理未注册的计划。

于 2013-03-02T16:12:26.843 回答
0

我也遇到过这样的问题,我得到了解决方案,这个检查你的代理设置的简单解决方案,这是因为网络代理设置的

只需删除代理并尝试 :) 它对我有用

于 2017-03-23T05:46:27.387 回答