我的播放控制台中没有收到此崩溃报告,但我在Android Studio中测试应用时收到此报告。我有一个"新闻"将用户带到使用JSoup从网站获取新闻链接的Activity的按钮。按下按钮后,它立即开始创建活动并崩溃。我不会在之前的活动中使用finish(),这样他们就可以回到他们完成时所做的事情。
以下是MainActivity中的Click Listener:
newsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent newsIntent = new Intent(MainActivity.this, NewsActivity.class);
startActivity(newsIntent);
}
});
这是我的NewsActivity:
public class NewsActivity extends AppCompatActivity {
ListView mListView;
Document document;
Elements newsTitles;
Elements newsLinks;
static Elements dates;
static Element date;
Elements datesStrings;
static Element link;
static String href;
private static final String TAG = "NewsActivity";
private ArrayList<Article> mArticleList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
HtmlParser htmlThread = new HtmlParser();
htmlThread.execute();
mListView = findViewById(R.id.articleListView);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Article a = mArticleList.get(position);
href = a.getHref();
Uri uri = Uri.parse(href);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
public class HtmlParser extends AsyncTask<Void, Integer, ArrayList<Article>> {
private static final int NETWORK_NO_ERROR = -1;
private static final int NETWORK_HOST_UNREACHABLE = 1;
private static final int NETWORK_NO_ACCESS_TO_INTERNET = 2;
private static final int NETWORK_TIME_OUT = 3;
Integer serverError = NETWORK_NO_ERROR;
ProgressDialog dialog;
protected void onPreExecute() {
dialog = new ProgressDialog(NewsActivity.this, R.style.CustomSpinnerStyle);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Getting Your News!");
dialog.show();
}
@Override
protected ArrayList<Article> doInBackground(Void... params) {
try {
//get the web document
document = Jsoup.connect("<URL HERE>").get();
//get titles
newsTitles = document.getElementsByClass("<SOME CSS CLASS HERE>");
//get newsLinks
newsLinks = newsTitles.select("a[href]");
//get the dates class
dates = document.getElementsByClass("<SOME CSS CLASS HERE>");
//get the date text
datesStrings = dates.select("time");
for(int i = 5; i < newsLinks.size() && i < datesStrings.size(); i++) {
link = newsLinks.get(i);
date = datesStrings.get(i - 5);
mArticleList.add(new Article(link.text(), link.attr("href"), date.text()));
}
return mArticleList;
} catch(ConnectException e) {
serverError = NETWORK_NO_ACCESS_TO_INTERNET;
return null;
} catch (UnknownHostException e) {
serverError = NETWORK_HOST_UNREACHABLE;
return null;
} catch(SocketTimeoutException e) {
serverError = NETWORK_TIME_OUT;
return null;
} catch (IOException e) {
e.printStackTrace();
}
return null;
} //end doInBackground
protected void onProgressUpdate(Integer... progress) {
} // end onProgressUpdate
protected void onPostExecute(ArrayList<Article> result) {
if(result != null) {
ListView listView = findViewById(R.id.articleListView);
listView.setAdapter(new ArrayAdapter<>(NewsActivity.this, R.layout.custom_textview, mArticleList));
if(dialog.isShowing()) {
dialog.dismiss();
}
} else {
switch(serverError) {
case NETWORK_NO_ERROR:
Toast.makeText(NewsActivity.this, "Oops. Invalid response from server.", Toast.LENGTH_LONG).show();
break;
case NETWORK_NO_ACCESS_TO_INTERNET:
Toast.makeText(NewsActivity.this, "No Internet connection found.", Toast.LENGTH_SHORT).show();
break;
case NETWORK_TIME_OUT:
case NETWORK_HOST_UNREACHABLE:
Toast.makeText(NewsActivity.this, "Error in connection.", Toast.LENGTH_LONG).show();
break;
}
}
}
}
}
这是完整的堆栈跟踪:
java.lang.StackOverflowError: stack size 8MB
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnec
同样,只有在使用Android 6.0作为我的模拟器时才会发生这种情况,而且我还没有从Play控制台收到崩溃报告。这是Android Studio中的一个设置吗?我可以俯瞰吗?
答案 0 :(得分:0)
好的,抱歉浪费你的时间。我禁用了#34; Advanced Profiling&#34;通过运行 - &gt;编辑配置 - &gt;分析 - &gt;取消选中&#34;启用高级分析。&#34;这不是一个野外问题,所以这是因为我自己的设置。