Android Studio - 当Get Request很长时,应用程序崩溃,否则工作正常

时间:2018-03-01 08:48:47

标签: java android http android-studio get

我有一个发送相对较长的Get请求的应用程序。 这是事情,当获取请求不长时,它完全正常,当Get请求包含大量数据时,它会崩溃应用程序... 我真的不知道为什么,而且我无法真正理解崩溃的原因。 这是我的Asynctask:

public class CreatePostAsyncTask extends AsyncTask<String, Void, CreatePostData> {


@Override
protected void onPreExecute() {
    p5= ProgressDialog.show(CreatePostActivity.this,"checks data",getString(R.string.loadingPleaseWait),true);
    p5.setCancelable(true);
    p5.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    p5.setMessage(getString(R.string.loadingDotDotDot));
    p5.show();

}

@Override
protected CreatePostData doInBackground(String... params)
{
    String str=params[0];
    String res=performCreatePostCall(str);
    Log.d("ress", res);
    CreatePostData regi = null;
    String Response = params[0];
    if (Response.matches(""))
    {
        regi = new CreatePostData("null", "null");
    }
    else {
        try {

            JSONObject json_data = new JSONObject(res);
            String Status = json_data.getString("status");
            String error = "null";
            if (Status.equals("ok"))
                error = "null";
            else
                error= json_data.getString("error");
            Log.d("coo", error);
            regi = new CreatePostData(Status, error);
            Log.d("stat", regi.getStatus());
        } catch (JSONException e) {

        }
        Log.d("aa", res);
    }
    return regi;
}

@Override
protected void onPostExecute(CreatePostData result) {
    Log.d("stat2", result.getStatus());

    if (result.getStatus().equals("ok")) {
        p5.dismiss();
        onBackPressed();
    }
    else if(result.getError().equals("Username already exists."))
    {
        Toast.makeText(CreatePostActivity.this, R.string.UserNameIsAlreadyCaught, Toast.LENGTH_LONG).show();

    }
    else if(result.getError().equals("E-mail address is already in use"))
    {
        Toast.makeText(CreatePostActivity.this, R.string.EmailIsAlreadyCaught, Toast.LENGTH_LONG).show();
    }
    else
    {
        Log.d("Didit", result.getError());
        Toast.makeText(CreatePostActivity.this, R.string.UnknownErrorCloseAndTryAgain, Toast.LENGTH_LONG).show();
    }
    if (p5.isShowing()){
        p5.dismiss();
    }

}
}

这是&#34; performCreatePostCall&#34;类:

public String performCreatePostCall(String requestURL) {

URL url;
Log.d("nugi", "Got Here 1");
String response = "";
try {
    Log.d("nugi", "Got Here 2");
    url = new URL(requestURL);
    Log.d("nugi", url.toString());

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(15000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.setDoOutput(true);

    int responseCode=conn.getResponseCode();
    Log.d("status3", String.valueOf(responseCode));
    if (responseCode == HttpsURLConnection.HTTP_OK) {
        Log.d("nugi", "Got Here 3");
        String line;
        BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream(), "iso-8859-1"));
        Log.d("nugi", "Got Here 4");
        while ((line=br.readLine()) != null) {
            response+=line;
            Log.d("nugi", "Got Here 5");
        }
        Log.d("nugi", response);

    }
    else {
        String line;
        BufferedReader br=new BufferedReader(new
                InputStreamReader(conn.getErrorStream(), "iso-8859-1"));
        Log.d("nugi", "Got Here 4");
        while ((line=br.readLine()) != null) {
            response+=line;
            Log.d("nugi", "Got Here 5");
        }
        Log.d("nugi", response);

    }

} catch (Exception e) {
    e.printStackTrace();
}

return response;
}

及以下是logcat错误:

  

03-01 08:32:19.291 15137-15194 / com.example.negev.peulibraryv201 E / TextClassifierImpl:建议选择文本时出错。建议不要改变选择。                                                                                         java.io.FileNotFoundException:没有用于null语言环境的文件                                                                                             在android.view.textclassifier.TextClassifierImpl.getSmartSelection(TextClassifierImpl.java:196)                                                                                             在android.view.textclassifier.TextClassifierImpl.suggestSelection(TextClassifierImpl.java:104)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationHelper.suggestSelection(SelectionActionModeHelper.java:650)                                                                                             在android.widget.SelectionActionModeHelper.-android_widget_SelectionActionModeHelper-mthref-0(SelectionActionModeHelper.java:88)                                                                                             在android.widget .- $ Lambda $ tTszxdFZ0V9nXhnBpPsqeBMO0fw $ 1. $ m $ 1(未知来源:4)                                                                                             在android.widget .- $ Lambda $ tTszxdFZ0V9nXhnBpPsqeBMO0fw $ 1.get(未知来源:16)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationAsyncTask.doInBackground(SelectionActionModeHelper.java:565)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationAsyncTask.doInBackground(SelectionActionModeHelper.java:560)                                                                                             在android.os.AsyncTask $ 2.call(AsyncTask.java:333)                                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:266)                                                                                             在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:245)                                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)                                                                                             at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:636)                                                                                             在java.lang.Thread.run(Thread.java:764)   03-01 08:32:19.292 15137-15194 / com.example.negev.peulibraryv201 E / TextClassifierImpl:获取辅助信息时出错。                                                                                         java.io.FileNotFoundException:没有用于null语言环境的文件                                                                                             在android.view.textclassifier.TextClassifierImpl.getSmartSelection(TextClassifierImpl.java:196)                                                                                             在android.view.textclassifier.TextClassifierImpl.classifyText(TextClassifierImpl.java:150)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationHelper.performClassification(SelectionActionModeHelper.java:688)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationHelper.suggestSelection(SelectionActionModeHelper.java:654)                                                                                             在android.widget.SelectionActionModeHelper.-android_widget_SelectionActionModeHelper-mthref-0(SelectionActionModeHelper.java:88)                                                                                             在android.widget .- $ Lambda $ tTszxdFZ0V9nXhnBpPsqeBMO0fw $ 1. $ m $ 1(未知来源:4)                                                                                             在android.widget .- $ Lambda $ tTszxdFZ0V9nXhnBpPsqeBMO0fw $ 1.get(未知来源:16)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationAsyncTask.doInBackground(SelectionActionModeHelper.java:565)                                                                                             在android.widget.SelectionActionModeHelper $ TextClassificationAsyncTask.doInBackground(SelectionActionModeHelper.java:560)                                                                                             在android.os.AsyncTask $ 2.call(AsyncTask.java:333)                                                                                             at java.util.concurrent.FutureTask.run(FutureTask.java:266)                                                                                             在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:245)                                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)                                                                                             at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:636)                                                                                             在java.lang.Thread.run(Thread.java:764)

您认为可能是什么原因? 谢谢!

0 个答案:

没有答案