0

でこのコードを書きましたAsyncTaskが、これがわかりませんException。誰かが私が間違っている場所を教えてもらえますか? 私は何をしなければならないのかわかりません。これが私の3つの方法AsyncTaskです。

protected void onPreExecute() {

        HttpParams params = httpClient.getParams();


        if(script.contains("appscan.php"))
        {
            Params.printLog(TAG,"onPreExecute appscan.php script:"+script);
            HttpConnectionParams.setConnectionTimeout(params, 10000);
            HttpConnectionParams.setSoTimeout(params, 10000);
        }
        else
        {
            Params.printLog(TAG,"onPreExecute  script:"+script);
            HttpConnectionParams.setConnectionTimeout(params, 120000);
            HttpConnectionParams.setSoTimeout(params, 120000);
        }
    }

    protected String doInBackground(Void... urls) {
        String st_response="";
        try {
            final HttpResponse response;
            //synchronized (httpClient) {
                if(request==null)
                     cancel(true);
                String m_url;
                if(isPost)
                {
                    m_url=baseUrl+script;
                    HttpPost httppost = new HttpPost(m_url);
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("id", "12345"));

                    httppost.setEntity(new UrlEncodedFormEntity((List<NameValuePair>)request));
                    if(getClient()==null)
                    {
                        return "";
                    }
                    response = getClient().execute(httppost);

                }
                else
                {
                    String m_request=request==null?"":Uri.encode(request.toString());
                    if(DEBUG)
                        m_url=baseUrl1+script+m_request;
                    else
                        m_url=baseUrl+script+m_request;

                    Params.printLog(TAG,"run :"+m_url);
                    HttpUriRequest request1=new HttpGet(m_url);
                    if(getClient()==null || request1==null)
                    {
                        return "";
                    }
                    response = getClient().execute(request1);
                }
                StringBuilder builder = new StringBuilder();
                InputStream is=response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                for (String line = null; (line = reader.readLine()) != null;) {
                    builder.append(line).append("\n");
                }
                is.close();
                st_response=builder.toString();
            //}
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnknownHostException e)
        {
            st_response="{\"httperr\":1}";
            e.printStackTrace();
        } 
        catch (IOException e) {
            st_response="{\"httperr\":1}";
            e.printStackTrace();
        }
        return st_response;
    }

    protected void onPostExecute(String content) {
        if(o==null)
            ((ResponseListener)listener).onResponseReceived(content);
        else
            ((ResponseWithObjectListener)listener).onResponseReceived(content,o);
     }

大量のデータを読み込もうとすると、次のエラーが発生します。

03-15 13:50:23.160: E/AndroidRuntime(4980): FATAL EXCEPTION: AsyncTask #4
03-15 13:50:23.160: E/AndroidRuntime(4980): java.lang.RuntimeException: An error occured while executing doInBackground()
03-15 13:50:23.160: E/AndroidRuntime(4980):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.lang.Thread.run(Thread.java:1019)
03-15 13:50:23.160: E/AndroidRuntime(4980): Caused by: java.lang.OutOfMemoryError
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:153)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.lang.StringBuilder.append(StringBuilder.java:217)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at com.qriket.qriket.httpclient.HttpAsyncTask.doInBackground(HttpAsyncTask.java:126)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at com.qriket.qriket.httpclient.HttpAsyncTask.doInBackground(HttpAsyncTask.java:1)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-15 13:50:23.160: E/AndroidRuntime(4980):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

ありがとう

4

1 に答える 1

0

応答が非常に大きいようです(文字列ビルダーは文字列全体を作成できません)。ファイルに保存して保存し、タスクの完了後にチャンクで読み取ることをお勧めします。

于 2013-03-15T18:11:40.313 に答える